Linux system admin command
时间:2010-12-13 来源:chennrui
1. output files
cat -- concatenate files and print on the standard output
tac -- concatenate and print file in reverse
nl -- number lines of file
head -- output the first part of file
tail -- output the last part of file
2. summarizing files
wc -- print newline, word, and byte counts for each file
eg. $wc -l -c test 30(line) 557(byte) test
3. sort files
sort -- sort lines of text files
eg.
sort缺省默认空格和tab键为分隔符。其他方式分隔,使用-t选项。缺省以第1列来排序,即-k1 |
4. unique files
uniq -- report or omit repeated lines
-d: only print duplicate lines
-u: only print unique lines
5. compare files
diff -- compare files line by line
-y: output in two colums
-c: output lines of copied context (上下文输出格式)
-u: output lines of unified context
eg. $ diff -y a.txt b.txt -W 50
abc | cba
$ diff -c a.txt b.txt *** a.txt 2010-12-13 22:15:13.000000000 +0800--- b.txt 2010-12-13 22:15:21.000000000 +0800 *************** *** 1,2 **** ! abc hello --- 1,2 ---- ! cba hello $ diff -u a.txt b.txt --- a.txt 2010-12-13 22:15:13.000000000 +0800 +++ b.txt 2010-12-13 22:15:21.000000000 +0800 @@ -1,2 +1,2 @@ -abc +cba test |
6. operating on characters
tr -- translate or delete characters
-c: 取SET1的反义,所有不在SET1中的字符
-d: delete characters in SET1
-s: 浓缩重复的字符。如果标准输入中连续重复出现SET1里所列的字符,则将其浓缩成一个。或者将其浓缩成SET1中的字符
ps:
$echo "chennnrui123" | tr -d "cr123" hennnui $echo "chennnrui123" | tr -s "[a-z]" chenrui123 $echo "abc123def" | tr -cs "[a-z]" " " abc def $echo "abc123def" | tr -cs "[a-z]" " " abc
def
|
Others
alias -- redefine command
eg. alias ls='ls -lh'