日历

二月
28293031123
45678910
11121314151617
18192021222324
252627282912

分类

python 执行过程

2014年2月23日 16:17 | Comments(4) | Category:python | Tags:

参考资料

Dive into python


在Dive into python第五章中有一个提取MP3信息的脚本,不是很理解现在整理一下思路

"""Framework for getting filetype-specific metadata.

Instantiate appropriate class with filename.  Returned object acts like a
dictionary, with key-value pairs for each piece of metadata.
    import fileinfo
    info = fileinfo.MP3FileInfo("/music/ap/mahadeva.mp3")
    print "\\n".join(["%s=%s" % (k, v) for k, v in info.items()])

Or use listDirectory function to get info on all files in a directory.
    for info in fileinfo.listDirectory("/music/ap/", [".mp3"]):
        ...

Framework can be extended by adding classes for particular file types, e.g.
HTMLFileInfo, MPGFileInfo, DOCFileInfo.  Each class is completely responsible for
parsing its files appropriately; see MP3FileInfo for example.

This program is part of "Dive Into Python", a free Python book for
experienced programmers.  Visit http://diveintopython.org/ for the
latest version.
"""

__author__ = "Mark Pilgrim (mark@diveintopython.org)"
__version__ = "$Revision: 1.3 $"
__date__ = "$Date: 2004/05/05 21:57:19 $"
__copyright__ = "Copyright (c) 2001 Mark Pilgrim"
__license__ = "Python"

import os
import sys
from UserDict import UserDict

def stripnulls(data):
    "strip whitespace and nulls"
    return data.replace("\00", " ").strip()

class FileInfo(UserDict):
    "store file metadata"
    def __init__(self, filename=None):
        UserDict.__init__(self)
        self["name"] = filename
    
class MP3FileInfo(FileInfo):
    "store ID3v1.0 MP3 tags"
    tagDataMap = {"title"   : (  3,  33, stripnulls),
                  "artist"  : ( 33,  63, stripnulls),
                  "album"   : ( 63,  93, stripnulls),
                  "year"    : ( 93,  97, stripnulls),
                  "comment" : ( 97, 126, stripnulls),
                  "genre"   : (127, 128, ord)}
    
    def __parse(self, filename):
        "parse ID3v1.0 tags from MP3 file"
        self.clear()
        try:
            fsock = open(filename, "rb", 0)
            try:
                fsock.seek(-128, 2)
                tagdata = fsock.read(128)
            finally:
                fsock.close()
            if tagdata[:3] == 'TAG':
                for tag, (start, end, parseFunc) in self.tagDataMap.items():
                    self[tag] = parseFunc(tagdata[start:end])
        except IOError:
            pass

    def __setitem__(self, key, item):
        if key == "name" and item:
            self.__parse(item)
        FileInfo.__setitem__(self, key, item)

def listDirectory(directory, fileExtList):
    "get list of file info objects for files of particular extensions"
    fileList = [os.path.normcase(f) for f in os.listdir(directory)]
    fileList = [os.path.join(directory, f) for f in fileList \
                if os.path.splitext(f)[1] in fileExtList]
    def getFileInfoClass(filename, module=sys.modules[FileInfo.__module__]):
        "get file info class from filename extension"
        subclass = "%sFileInfo" % os.path.splitext(filename)[1].upper()[1:]
        return hasattr(module, subclass) and getattr(module, subclass) or FileInfox
    return [getFileInfoClass(f)(f) for f in fileList]

if __name__ == "__main__":
    for info in listDirectory("/home/been/Desktop/", [".mp3"]):
        print "\n".join(["%s=%s" % (k, v) for k, v in info.items()])
        print

用户执行代码从这里开始

if __name__ == "__main__":
    for info in listDirectory("/home/been/Desktop/", [".mp3"]):

一个for循环代码跳到了自定义的function上

def listDirectory(directory, fileExtList):
    "get list of file info objects for files of particular extensions"
    fileList = [os.path.normcase(f) for f in os.listdir(directory)]
     """这里返回在目录directory下的所有文件,文件夹的小写名称到fielList"""
    fileList = [os.path.join(directory, f) for f in fileList \
                if os.path.splitext(f)[1] in fileExtList]
     """这里返回的是所有带地址的mp3格式的文件名,如/home/been/Desktop/wake me up.mp3"""
    def getFileInfoClass(filename, module=sys.modules[FileInfo.__module__]):
        "get file info class from filename extension"
        subclass = "%sFileInfo" % os.path.splitext(filename)[1].upper()[1:]
     """subclass 的内容是MP3FileInfo"""
        return hasattr(module, subclass) and getattr(module, subclass) or FileInfox
     """hastter()和getatter()是检查subclass这个模块是否可用,是就返回hasatter()否则返回FileInfo
        不过这里不仅仅是返回那么简单,同时还是调用了MP3FileInfo这个模块"""
    return [getFileInfoClass(f)(f) for f in fileList]

python执行代码到这里

class MP3FileInfo(FileInfo):
    "store ID3v1.0 MP3 tags"
    tagDataMap = {"title"   : (  3,  33, stripnulls),
                  "artist"  : ( 33,  63, stripnulls),
                  "album"   : ( 63,  93, stripnulls),
                  "year"    : ( 93,  97, stripnulls),
                  "comment" : ( 97, 126, stripnulls),
                  "genre"   : (127, 128, ord)}

MP3FileInfo从FileInfo中继承了它的方法,代码又跑到了这里

class FileInfo(UserDict):
    "store file metadata"
    def __init__(self, filename=None):
        UserDict.__init__(self)
        self["name"] = filename

同样FileInfo又从UserDict中继承了它的方法,UserDict是一个python自定义的class,用来创建字典的类。

可以用pydoc UserDict查看它的方法和属性。可以在/usr/lib/python2.7/UserDict.py 查看源代码

这部分代码生成了一个字典{filename:none}

接着代码回到了这里

class MP3FileInfo(FileInfo):
    "store ID3v1.0 MP3 tags"
    tagDataMap = {"title"   : (  3,  33, stripnulls),
                  "artist"  : ( 33,  63, stripnulls),
                  "album"   : ( 63,  93, stripnulls),
                  "year"    : ( 93,  97, stripnulls),
                  "comment" : ( 97, 126, stripnulls),
                  "genre"   : (127, 128, ord)}
    
    def __parse(self, filename):
        "parse ID3v1.0 tags from MP3 file"
        self.clear()
        try:
            fsock = open(filename, "rb", 0)
            try:
                fsock.seek(-128, 2)
                tagdata = fsock.read(128)
            finally:
                fsock.close()
            if tagdata[:3] == 'TAG':
                for tag, (start, end, parseFunc) in self.tagDataMap.items():
                    self[tag] = parseFunc(tagdata[start:end])
        except IOError:
            pass

    def __setitem__(self, key, item):
        if key == "name" and item:
            self.__parse(item)
        FileInfo.__setitem__(self, key, item)

在这里代码首先在__setitem__执行,疑问出来了书上说__setitem__是被MP3FileInfo覆盖的,但是__setitem__()却要和父类UserDict中的__setitem__()的参数的个数要一样。下面这两个是为了解决临界问题

当首次执行__setitem__时key为not defined,item在__parse已经创建。理解if这一句需要知道== and的优先顺序,这一句的意思是:如果key=="name"则执行self.__parse(item)否则执行File~。

因为FileInfo没有__setitem__类,因此需要到父类UserDict中去找。到这里所有的信息都存在了FileInfo字典中。

最后的代码

if __name__ == "__main__":
    for info in listDirectory("/home/been/Desktop/", [".mp3"]):
        print "\n".join(["%s=%s" % (k, v) for k, v in info.items()])
        print

for语句这里的info in ListDirectory(),相当于info=MP3FileInfo(),所以info有info.items()属性


后记:把博文写出来的确是对代码理解透彻了很多,因为只学过c,对类这种编程思想跟本没有了解过,一直在纠结干嘛要创建字典,是怎么通过类给字典里的key:value赋值,是怎么提取里面的元素的

补充python运算符的优先顺序:从上往下递增

运算符 描述
lambda Lambda表达式
or 布尔“或”
and 布尔“与”
not x 布尔“非”
in,not in 成员测试
is,is not 同一性测试
<,<=,>,>=,!=,== 比较
| 按位或
^ 按位异或
& 按位与
<<,>> 移位
+,- 加法与减法
*,/,% 乘法、除法与取余
+x,-x 正负号
~x 按位翻转
** 指数
x.attribute 属性参考
x[index] 下标
x[index:index] 寻址段
f(arguments...) 函数调用
(experession,...) 绑定或元组显示
[expression,...] 列表显示
{key:datum,...} 字典显示
'expression,...' 字符串转换

 

代码执行过程

2014年2月23日 13:26 | Comments(1) | Category:python | Tags:

参考资料:

Dive into python


Dive into python 第五章中的有一个脚本,是提取MP3文件中的信息的。一直很不理解,现在希望整理一下思路

"""Framework for getting filetype-specific metadata.

Instantiate appropriate class with filename.  Returned object acts like a
dictionary, with key-value pairs for each piece of metadata.
    import fileinfo
    info = fileinfo.MP3FileInfo("/music/ap/mahadeva.mp3")
    print "\\n".join(["%s=%s" % (k, v) for k, v in info.items()])

Or use listDirectory function to get info on all files in a directory.
    for info in fileinfo.listDirectory("/music/ap/", [".mp3"]):
        ...

Framework can be extended by adding classes for particular file types, e.g.
HTMLFileInfo, MPGFileInfo, DOCFileInfo.  Each class is completely responsible for
parsing its files appropriately; see MP3FileInfo for example.

This program is part of "Dive Into Python", a free Python book for
experienced programmers.  Visit http://diveintopython.org/ for the
latest version.
"""

__author__ = "Mark Pilgrim (mark@diveintopython.org)"
__version__ = "$Revision: 1.3 $"
__date__ = "$Date: 2004/05/05 21:57:19 $"
__copyright__ = "Copyright (c) 2001 Mark Pilgrim"
__license__ = "Python"

import os
import sys
from UserDict import UserDict

def stripnulls(data):
    "strip whitespace and nulls"
    return data.replace("\00", " ").strip()

class FileInfo(UserDict):
    "store file metadata"
    def __init__(self, filename=None):
        UserDict.__init__(self)
        self["name"] = filename
    
class MP3FileInfo(FileInfo):
    "store ID3v1.0 MP3 tags"
    tagDataMap = {"title"   : (  3,  33, stripnulls),
                  "artist"  : ( 33,  63, stripnulls),
                  "album"   : ( 63,  93, stripnulls),
                  "year"    : ( 93,  97, stripnulls),
                  "comment" : ( 97, 126, stripnulls),
                  "genre"   : (127, 128, ord)}
    
    def __parse(self, filename):
        "parse ID3v1.0 tags from MP3 file"
        self.clear()
        try:
            fsock = open(filename, "rb", 0)
            try:
                fsock.seek(-128, 2)
                tagdata = fsock.read(128)
            finally:
                fsock.close()
            if tagdata[:3] == 'TAG':
                for tag, (start, end, parseFunc) in self.tagDataMap.items():
                    self[tag] = parseFunc(tagdata[start:end])
        except IOError:
            pass

    def __setitem__(self, key, item):
        if key == "name" and item:
            self.__parse(item)
        FileInfo.__setitem__(self, key, item)

def listDirectory(directory, fileExtList):
    "get list of file info objects for files of particular extensions"
    fileList = [os.path.normcase(f) for f in os.listdir(directory)]
    fileList = [os.path.join(directory, f) for f in fileList \
                if os.path.splitext(f)[1] in fileExtList]
    def getFileInfoClass(filename, module=sys.modules[FileInfo.__module__]):
        "get file info class from filename extension"
        subclass = "%sFileInfo" % os.path.splitext(filename)[1].upper()[1:]
        return hasattr(module, subclass) and getattr(module, subclass) or FileInfox
    return [getFileInfoClass(f)(f) for f in fileList]

if __name__ == "__main__": for info in listDirectory("/home/been/Desktop/", [".mp3"]):

print "\n".join(["%s=%s" % (k, v) for k, v in info.items()]) print

用户执行脚本,到达这里

can't disable telnet please help~~

2014年2月09日 01:14 | Comments(0) | Category:linux | Tags:

参考资料

1.install and enalbe telent

2.enable ssh&telnet

3.diable telent


ubuntu系统在默认情况下是没有启动telent服务的,需要自行配置

1.安装启动基础服务

sudo apt-get install xinetd

2.配置基础文件,在/etc/xinet.conf加入如下几行

# Simple configuration file for xinetd

#

# Some defaults, and include /etc/xinetd.d/

defaults

{

# Please note that you need a log_type line to be able to use log_on_success

# and log_on_failure. The default is the following :

# log_type = SYSLOG daemon info

instances = 60

log_type = SYSLOG authpriv

log_on_success = HOST PID

log_on_failure = HOST

cps = 25 30

}

3.安装telent客户端

sudo apt-get install telnet

4.配置telent文件,nano /etc/xinetd.d/telnet,在此目录下没有telent文件的自己touch

# default: on
# description: The telnet server serves telnet sessions; it uses
# unencrypted username/password pairs for authentication.
service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

更高安全要求配置

only_from = 192.168.120.0/24 #Only users in 192.168.120.0 can access to

only_from = .bob.com #allow access from bob.com

no_access = 192.168.120.{101,105} #not allow access from the two IP.

access_times = 8:00-9:00 20:00-21:00 #allow access in the two times

5.重启xinet服务

sudo /etc/init.d/xinetd restart

6.关闭telent服务,网上的教程是这样做的,但是我却不成功,求搭救~~

把/etc/xinetd.d/telnet 文件的 disable=no 改为yes

重启xinetd服务 sudo /etc/init.d/xinetd restart

> ps:重启xinetd服务 service xinetd restart 也可以,不过我的ubuntu不知道为什么,用tab能调出xinetd但是执行命令却是

stop: Unknown job: xinetd

start: Unknown job: xinetd

>ps 网上的重启xinetd服务是 sudo /etc/rc.d/init.d/xinetd restart 但是我/etc下没有rc.d 不过有rc0~6.d,不知道这个有没有关系呢

 

 

shell 基础

2013年12月26日 20:44 | Comments(0) | Category:linux | Tags:

参考资料 :UNIX和shell程序设计权威教程 清华大学出版社

鸟哥的私房菜


 

1.验证当前shell

echo $0

2.重定向

类型 Korn shell or Bash shell
输入 0<file1
输出 1>>file1(追加) or 1>|file1(覆盖)
错误输入 2>>file1(追加形式) or 2>|file2(覆盖形式)
输出错误(不同文件) 1> file1 2>file2
输出错误(同一个文件) 1>file1 2&1

重定向到垃圾桶 /dev/null

3.管道

注意管道的左边命令必须能够发送数据至标准输出,右端命令必须能从标准输入接收数据

4.引号:斜干(\)、单引号('')、双引号("")
斜杆主要是用来转义、如果需要输出单引号,双引号也需要在引号前面加上 \
 
单双引号可以使其内的所有特殊字符失去特殊作用。不过单引号的能力比双引号的能力更强。爽引号保留诸如空格、制表符、换行符、自定义变量。单引号则不能
 
5.命令替代:在一段文本中使用某个命令 $(command)
 
6.作业控制
只有将工作挂起才能将工作置于前台或后台工作 (fg %n   bg  %n)
从前台后台停止工作 (ctrl+z stop)
从前台后台终止工作(ctrl +d kill)
 
7.别名
给命令自定义自己喜欢的名字(如果命令是家参数的需要用单引号或双引号) alias name=command
取消别名unalias name
显示所有的命令别名 alias
 
8.变量
8.1修改系统级变量
《私房菜》P377
增加变量 方式  -> 变量名=$"变量名":增加内容
将变量转变成环境变量 export 变量名
方式 结果
$(variable#key) 从变量的开头删除一直到key之后
$(variable##key) 从变量的开头删除最长的字符串一直到key之后
$(variable%key) 从变量的尾部开始删除一直到key之前
$(variable%%key) 从变量的尾部开始删除最长的字符串一知道key之前
$(varible/old_k/new_key)

用new_key替换第一个符合的old_k

$(varible//old_key/new_key) 用new_key替换所有的old_k

 

8.2修改个人变量
8.3变量的测试
 
9终端的区别
终端分为两种一种是需要登录的终端(login shell)指的是tty1~6,一种是不需要登录的(no-login shell),指的是在x-windows下启动的图形终端。两种终端启动的配置文件是不同的
login shell 对应 /etc/profile
no-login shell对应~/.bash_profile or ~/.bash_login or ~/.profile  (优先顺序从左到右)
 
详见《私房菜》P384 ~392 Bash Shell的环境操作
 
 
 
《私房菜》P380                              ps:乱码语系P371
 

grep

2013年12月25日 15:56 | Comments(1) | Category:linux | Tags:

The useful options of grep,egrep,fgrep

-i, Ignore case distinctions in both the patten and files

-v Invert the sense of matching,to selsect non-matching lines

-c Suppress normal output;instead print a count of matching line

-n Prefix each line of output with the 1-based line number

正则表达式

2013年12月22日 23:27 | Comments(0) | Category:linux | Tags:

参考书籍:unix和shell程序设计权威指南 清华出版社

                    正则表达式


一、原子

点:. 匹配任意ACII字符

类:[]匹配方括号内任意一个字符

     注:方括号内使用转义字符\,非运算符^

             [A-Za-z]:任意字符

锚:^  : 行首

         $  :行尾

         \<  :单词词首

        \>   :单词词尾

                     注:锚和原子经常结合一起使用,如^Q表示已Q开头的一个字符串

向后引用

重新使用在一个正则表达式定义过的规则,不过这是有要求的,规则必须出现在()中,/1调用第一个括号里的规则、/2 /3……以此类推。加入多个括号嵌套使用系统会自动给最先出现的'('分配.

二、正则表达式的运算符

序列运算符:序列算符为空,它的含义是:如果有原子系列出现在正则表达式中则表示在原子之间有一个不可见的序列运算符

    注:[0-9][0-9]任意数字

替换:|   相当于是 A or B,AB中的任意一个

重复:\{m,n\}

             说明:最多n个可以是0到n \{,n\}

                          最少n个必须比n个多\{n,\}

                          精确n个\{n\}

缩写形式运算符:?匹配前面的原子0到1次

                                  +匹配前面的原子1到多次

                                  *匹配前面的原子0到多次

组运算符:()相当于四则运算里的括号,被括起来的部分先进行运算

                    注:*(?=xxxx)匹配*的右边必须是xxxx *(?>=xxxx)匹配的左边必须是xxxx


 

\r,\n carriage return,newline character
\t Tabs
\d Any digit character,any ont of 0~9
\w any alpha,numeric,underline
\s Any one of space,tab,newline, or\n
. Any character except \n
\b Match a word boundary
   
   
   

English Version

common 普通字符

escaped character 转义字符

character sets 字符集合

custom sets 次数集合

quantifier

special puncts 特殊字符(点)

backward 向后引用

assertion  预搜索

greedy  reluctant 贪婪 懒惰

prompts 提示


 


 

日志

2013年12月17日 20:20 | Comments(0) | Category:linux | Tags:

这是我删除的软件包的日志,以后再也不乱删东西了后果真的很严重@依云说可以查看apt日志自己删除了什么包然后从新安装这些包就可以了。但是我都不知道那些包是有用的那些是可以删的。现在知道更声卡有关的就只有 
inux-sound-base
alsa-base
alsa-utils
在ubuntu官网上这个包有嵌套那个包啊,是在是搞不清他们的依赖关系。
只能是从新安装 alsa驱动了
 
 
Start-Date: 2013-12-08  15:12:06
Commandline: apt-get autoremove
Remove: efibootmgr:amd64 (0.5.4-4ubuntu1), libvte-common:amd64 (0.28.2-5ubuntu1), libconfuse-common:amd64 (2.7-4), libvte9:amd64 (0.28.2-5ubuntu1), libconfuse0:amd64 (2.7-4), grub-efi-amd64-bin:amd64 (2.00-13ubuntu3)
End-Date: 2013-12-08  15:12:17
 
Start-Date: 2013-12-08  15:26:05
Commandline: apt-get install aptitude
Install: aptitude:amd64 (0.6.8.1-2ubuntu2), libcwidget3:amd64 (0.5.16-3.4ubuntu1, automatic), libboost-iostreams1.49.0:amd64 (1.49.0-3.2ubuntu1, automatic), libept1.4.12:amd64 (1.0.9, automatic), aptitude-common:amd64 (0.6.8.1-2ubuntu2, automatic)
End-Date: 2013-12-08  15:26:15
 
Start-Date: 2013-12-08  15:27:02
Purge: vim-gui-common:amd64 (), vim-common:amd64 (), libwxbase2.8-0:amd64 (), grub-efi-amd64:amd64 (), libwxsqlite3-2.8-0:amd64 (), libeventviews4:amd64 (), libcalendarsupport4:amd64 (), vim-tiny:amd64 (), tilda:amd64 (), libkdepim4:amd64 (), libwxgtk2.8-0:amd64 (), guayadeque:amd64 (), vim-gnome:amd64 (), libincidenceeditorsng4-mobile:amd64 (), libvte9:amd64 (), libkdepimdbusinterfaces4:amd64 (), libkdgantt2:amd64 (), im-switch:amd64 (), libkdepimui-mobile:amd64 (), libconfuse0:amd64 (), vim-runtime:amd64 ()
End-Date: 2013-12-08  15:27:29
 
Start-Date: 2013-12-08  15:27:41
Purge: linux-image-extra-3.8.0-19-generic:amd64 (3.8.0-19.30), linux-headers-3.8.0-19:amd64 (3.8.0-19.30), linux-headers-3.8.0-30:amd64 (3.8.0-30.44), linux-headers-3.8.0-29:amd64 (3.8.0-29.42), linux-image-3.8.0-29-generic:amd64 (3.8.0-29.42), linux-image-3.8.0-19-generic:amd64 (3.8.0-19.30), linux-headers-3.8.0-29-generic:amd64 (3.8.0-29.42), linux-image-extra-3.8.0-30-generic:amd64 (3.8.0-30.44), linux-headers-3.8.0-19-generic:amd64 (3.8.0-19.30), linux-image-3.8.0-30-generic:amd64 (3.8.0-30.44), linux-image-extra-3.8.0-29-generic:amd64 (3.8.0-29.42), linux-headers-3.8.0-30-generic:amd64 (3.8.0-30.44)
Error: Sub-process /usr/bin/dpkg returned an error code (1)
End-Date: 2013-12-08  15:29:09
 
Start-Date: 2013-12-08  15:39:46
Commandline: aptdaemon role='role-remove-packages' sender=':1.385'
Remove: linux-image-extra-3.8.0-19-generic:amd64 (3.8.0-19.30), linux-image-3.8.0-19-generic:amd64 (3.8.0-19.30), unity-webapps-common:amd64 (2.4.14-0ubuntu1)
End-Date: 2013-12-08  15:39:52
 
Start-Date: 2013-12-08  15:42:02
Commandline: aptdaemon role='role-remove-packages' sender=':1.385'
Remove: libopenal1:amd64 (1.14-4ubuntu1), libopenal1:i386 (1.14-4ubuntu1), libpam-winbind:amd64 (3.6.9-1ubuntu1.1), ttf-umefont:amd64 (444-1ubuntu1), wine1.4-amd64:amd64 (1.4.1-0ubuntu5), ttf-liberation:amd64 (1.07.2-6ubuntu1), wine1.4:amd64 (1.4.1-0ubuntu5), libcapi20-3:amd64 (3.12.20071127-0ubuntu11), libopenal-data:amd64 (1.14-4ubuntu1), unixodbc:amd64 (2.2.14p2-5ubuntu4), wine-gecko1.4:amd64 (1.4.0-0ubuntu2), winetricks:amd64 (0.0+20121030+svn918-2), wine1.4-i386:i386 (1.4.1-0ubuntu5), ttf-unfonts-core:amd64 (1.0.3.is.1.0.2-080608-5ubuntu3), winbind:amd64 (3.6.9-1ubuntu1.1), libodbc1:amd64 (2.2.14p2-5ubuntu4), libnss-winbind:amd64 (3.6.9-1ubuntu1.1), ttf-droid:amd64 (4.2.r1-1ubuntu1)
End-Date: 2013-12-08  15:42:28
 
Start-Date: 2013-12-08  15:48:10
Commandline: aptdaemon role='role-remove-packages' sender=':1.385'
Remove: claws-mail-i18n:amd64 (3.8.1-2), claws-mail:amd64 (3.8.1-2)
End-Date: 2013-12-08  15:48:16
 
Start-Date: 2013-12-08  16:18:19
Commandline: aptdaemon role='role-remove-packages' sender=':1.385'
Remove: totem-plugins:amd64 (3.6.3-0ubuntu6), totem:amd64 (3.6.3-0ubuntu6), totem-mozilla:amd64 (3.6.3-0ubuntu6)
End-Date: 2013-12-08  16:18:24
 
Start-Date: 2013-12-08  17:27:31
Commandline: apt-get install deborphan -y
Install: deborphan:amd64 (1.7.28.8)
End-Date: 2013-12-08  17:27:41
 

清理linxu垃圾文件

2013年12月08日 18:52 | Comments(4) | Category:linux | Tags:

今天用df命令查看了自己的磁盘空间发现/分区已经使用了91%,特意上网找了一些方法以下是总结

1.使用命令 du --max-depth=1 -h 来查看各个目录的大小

参数说明  --max-depth=x ,x可以是0~n的数字,表示查看子目录的深度

                   -h 表示适合阅读

 
2.删除垃圾文件所在的目录
    rm -rf /tmp/*
    rm -rf /var/log/*
    rm -rf /home/.mozilla/firefox/*
 
3.清理旧版本的软件缓存
sudo apt-get autoclean
4.清理所有软件缓存
sudo apt-get clean
5.删除系统不再使用的孤立软件
sudo apt-get autoremove
6.清理linux下孤立的包
sudo apt-get install deborphan -y
7.删除多余的内核
          查看内核文件 (有image的就是内核文件)
dpkg --get-selections|grep linxu
          删除内核文件
sudo apt-get remove  内核文件名
参考IBM的文章 给linux系统“减肥”

linux系统剪切板与vim剪切板

2013年12月08日 12:56 | Comments(3) | Category:linux | Tags:

这都是一些零散的知识

1.在vim中的复制粘贴就是在寄存器中寄放和提取字符串。你可以用:reg来查看所有的寄存器

在vim复制一个字符串 "Ny  :N表示寄存器名称

在vim粘贴一个字符串  "Np

2.其中"+是也是x-windows中的寄存器,通过"+p可以在vim中调用系统中通过ctrl+c得到的内容

注意:在vim中,"+y 是复制一整行

3.yw可以复制一个字符串,不过需要光标在字符串的首字符

4.dw删除一个单词

i don konw

2013年12月02日 16:02 | Comments(3) | Category:linux | Tags:

#include <stdio.h>
int main()
{
printf("goagent");
}
basice
for (int i=1;i<10;i++)