查看文件内容:cat file1

查看内容并标示行数:cat -n file1

显示文件linuxbox.txt的内容:cat linuxbox.txt

从最后一行开始反看文件内容:tac file1

查看一个长文件的内容:more file1

类似more命令,但允许反向操作:less file1

查看文件前两行:head -2 file1

查看文件后两行:tail -2 file1

实时查看添加到文件中的内容:tail -f /log/msg

在文件hello.txt中查找关键词linuxbox:grep linuxbox hello.txt

在文件hello.txt中查找以linuxbox开头的内容:grep ^linuxbox hello.txt

选择hello.txt文件中所有包含数字的行:grep [0-9] hello.txt

将hello.txt文件中的s1替换成s2:sed ‘s/s1/s2/g’ hello.txt

从hello.txt文件中删除所有空白行:sed ‘/^$/d’ hello.txt

从hello.txt文件中删除所有注释和空白行:sed ‘/ *#/d; /^$/d’ hello.txt

从文件hello.txt 中排除第一行:sed -e ‘1d’ hello.txt

查看只包含关键词”s1″的行:sed -n ‘/s1/p’ hello.txt

删除每一行最后的空⽩字符:sed -e ‘s/ *$//’ hello.txt

从文档中只删除词汇s1并保留剩余全部:sed -e ‘s/s1//g’ hello.txt

查看从第一行到第五行内容:sed -n ‘1,5p;5q’ hello.txt

查看第五行:sed -n ‘5p;5q’ hello.txt

合并两个文件或两栏的内容:paste file1 file2

合并两个文件或两栏的内容,中间用”+”区分:paste -d ‘+’ file1 file2

排序两个文件的内容:sort file1 file2

比较两个文件的内容(去除’file1’所含内容):comm -1 file1 file2

比较两个文件的内容(去除’file2’所含内容):comm -2 file1 file2

比较两个文件的内容(去除两文件共有部分):comm -3 file1 file2