文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Linux system admin command

Linux system admin command

时间:2010-12-13  来源:chennrui

Linux Command

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
-n 指定分类是域上的数字分类。
如编辑文件1111.txt
sdsad 311 315 asd3f
wdasd 551 133 adsff
sdsad 606 44 fgfdgdf
wdwew 77 599 gghgf
eeese 23 22 fgdf
eeese 23 22 fgdf
dfdff 78 55 fdgd
   -k 使用k做分类排序,如按第2列来分类排序
$ sort -k2 1111.txt
eeese 23 22 fgdf
eeese 23 22 fgdf
sdsad 311 315 asd3f
wdasd 551 133 adsff
sdsad 606 44 fgfdgdf
wdwew 77 599 gghgf
dfdff 78 55 fdgd
    -n 指定分类列上按数值来分类排序,如第按第2列数值大小来分类
$ sort -k2n 1111.txt
eeese 23 22 fgdf
eeese 23 22 fgdf
wdwew 77 599 gghgf
dfdff 78 55 fdgd
sdsad 311 315 asd3f
wdasd 551 133 adsff
sdsad 606 44 fgfdgdf
    -u 去除重复的行,即完全一样的行,只保留一行
$ sort -k2n -u 1111.txt
eeese 23 22 fgdf 只有1行了
wdwew 77 599 gghgf
dfdff 78 55 fdgd
sdsad 311 315 asd3f
wdasd 551 133 adsff
sdsad 606 44 fgfdgdf


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.
a.txt
    abc
    hello
b.txt
    cba
    hello

$ diff -y a.txt b.txt -W 50

abc              |    cba
hello            hello


$ 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'
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载