cat[option]...[file]...
-E 显示行结束符$
-A 显示所有控制符
-n 对显示出的每一行进行编号
-b 非空行编号
-s 压缩连续的空行成一行
nl 同cat -b
tac 与cat相反,内容反过来查看
rev 行的内容倒过来显示
more[option...] file...
-d 显示翻页及退出提示
less 一页一页地查看文件或STDIN输出
head [option]...[file]...
-c # 指定获取前#字节
-n # 指定获取前#行
-# 指定行数
tail [option]... [file]...
-c # 指定获取后#字节
-n # 指定获取后#行
-# 同上
-f 跟踪显示文件fd新追加的内容,常用于日志监控,同:--follow=descriptor
-F 跟踪文件名,同:--follow=name --retry
tailf 类似tail -f ,文件不增长时,并不访问文件
随机信息
cat /dev/urandom
tr -dc '[:alnum:]' </dev/urandom |head -c12
文件描述符
pidof tail
ls /proc/`pidof tail`/fd -l
cut [option]...[file]...
-d DELIMITER 指明分隔符,默认tab
-f fileds
# 第#个字段
#,#[,#] 离散的多个字段 例如:1,3,5
#-# 连续的多个字段 例如:1-6
混合使用, 例如:1-3,7
-c 按字符切割
--output-delimiter=STRING 指定输出分隔符
paste 合并两个文件同行号的列到一行
paste [option]...[file]...
-d 分隔符, 指定分隔符,默认用TAB
-s 所有行合成一行显示
[root @ centos7 data]#cat ta2.txt xis kjskla alskjd asdw dklas kaj [root @ centos7 data]#cat tao.txt a d b [root @ centos7 data]#cat ta2.txt tao.txt xis kjskla alskjd asdw dklas kaj a d b [root @ centos7 data]#paste ta2.txt tao.txt xis a kjskla d alskjd b asdw dklas kaj
wc 计数单词、行、字节、字符总数
可以对文件或STDIN中的数据运行
-l 行数
-w 单词数
-c 字节数
-m 字符数
-L 显示文件中最长行的长度
sort 排序
sort [options] files
-r 反向整理
-R 随机排序
-n 数字大小排序
-f 忽略字符串中的字符大小写
-u 删除输出中重复的行
-t c 用c作为字段界定符
-k X 按c字符分隔的X列来整理,能使用多次
uniq 从输入中删除前后相接的重复的行
uniq [option]...[file]...
-c 显示每行重复出现的次数
-d 仅显示重复过的行
-u 仅显示不曾重复的行
连续且完全相同方为重复
diff 比较两个文件的不同
-u
patch 复制在其他文件中进行的改变(谨慎使用)
-b 自动备份改变了的文件
[root @ centos7 data]#cat a.txt a b c [root @ centos7 data]#cat b.txt a bb ccc dddd [root @ centos7 data]#diff -u a.txt b.txt --- a.txt 2021-04-04 08:45:38.933930921 +0800 +++ b.txt 2021-04-04 08:45:52.263930672 +0800 @@ -1,3 +1,4 @@ a -b -c +bb +ccc +dddd [root @ centos7 data]#diff -u a.txt b.txt > diff.log [root @ centos7 data]#ls a.txt b.txt diff.log [root @ centos7 data]#rm -rf b.txt [root @ centos7 data]#ls a.txt diff.log [root @ centos7 data]#patch -b a.txt diff.log patching file a.txt [root @ centos7 data]#ls a.txt a.txt.orig diff.log [root @ centos7 data]#cat a.txt.orig a b c [root @ centos7 data]#cat a.txt a bb ccc dddd