日期:2014-05-16  浏览次数:20701 次

学习Linux命令,读《系统程序员成长计划》

linux命令小结:

cat :查看文件并输出 cat test.txt > tmp.c
chmod :更改文件调用权限,rwx,421,chmod a+7 test.txt
chown :更改文件所有者
find :查找文件,find [path] [expression],eg: find . -name test.txt
cut :显示每行从开头算起 num1 到 num2 的文字, cut -c3-6 test.txt
ln :生成链接文件,分软/硬链接,默认为硬,加参数 -s 生成软,ln [-s] srcFile destFile
less :分页查看文件,可上下翻页
mkdir :创建目录
mv :移动或重命名文件
od :以八进制字码输出文件内容
paste :把每个文件以列对列的方式,一列列地加以合并,-d 分隔符
rcp :远程复制
rm :删除文件,加上参数 -rf 可删除非空目录
tee :从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件,eg: tee -a fileName
touch :改变文件的时间记录或创建文件
umask :指定在建立文件时预设的权限掩码
whick :在环境变量$PATH设置的目录里查找符合条件的文件
cp :copy文件, cp srcFile destFile

?

?

Linux命令:

cd :进入目录
df :显示硬盘使用情况,-h可显示更好
du :disk usage,显示目录或文件所占的磁盘空间
pwd :print working directory,打印当前目录
mount :挂载设备
stat :显示文件状态
tree :显示目录树
umount :卸载设备
ls :显示当前文件与目录
csplit :分割文件
fmt :指定格式编排后输出
grep :文本查找工具,参数:-c :只显示匹配的行数,-n :在匹配行前打印行号

?

python语言学习:

数组访问:word = ['a','b','c','d','我'], word[1:3]返回index为1,2的元素

字符串和整数不能直接相连,要通过str()和int()函数

# -*- coding:utf8 -*-
s = raw_input("请输入中文名字")

上面两行代码:设置中文不会乱码;获得输入

类的定义与初始化函数:

#!/usr/bin/python
class Person:
??? def __init__(self):
??? ??? print "this is init"
??? def sayHi(self):
??????? print "hello, how are you?"

p = Person()
p.sayHi()

异常:

#!/usr/bin/python
s = raw_input("input your age:")
if s == "":
??? raise Exception("input must not be empty.")

try:
??? i = int(s)
except ValueError:
??? print "could not convert data to an int"
except:
??? print "unknown exception"
else:
??? print "your age is %d" %i, ", this is python"
finally:
??? print " goodbye"

函数定义:

def sum(a,b):
??? return a+b

for循环:

a = ['cat', 'window', 'banana']
for x in a:
??? print x,len(x)

?

数据储存:

#!/usr/bin/python
import cPickle as p

shopListFile = 'shopList.data'
shopList = ['apple','mango','carrot']

f = file(shopListFile, 'w')
p.dump(shopList, f)
f.close()

del shopList

f = file(shopListFile)
storedList = p.load(f)
print storedList

?

Map的使用:

#!/usr/bin/python
x={'a':'aaa', 'b':'bbb', 'c':12}
print x['a']
print x['b']
print x['c']

for key in x:
?print "key is %s and value is %s" %(key,x[key])

keys = x.items()
print keys[0]

?

range()函数:a = range(5,10) :5,6,7,8,9。? range(-2,-7):空, range(-2,-11,-3):-2,-5,-8(说明:-3是步进)

?

读写文件:

#!/usr/bin/python
poem='''\
Programming is fun
when the work is done
if you wanna make your work also fun:
??? use Python!
'''
f = file('poem.txt','a')
f.write(poem)
f.close()

f = file('poem.txt')
while True:
??? line = f.readline()
??? if len(line) == 0:
??????? break
??? print line
f.close()

?