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 $ sort -k2n 1111.txt $ sort -k2n -u 1111.txt |
4. unique filesuniq -- report or omit repeated lines
-d: only print duplicate lines
-u: only print unique lines
5. compare filesdiff -- 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 --- 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
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.
沒有留言:
張貼留言