linux常见命令(十一)

tee/tr/col/paste/grep
双向重导向,既要重定向到文件,也要显示到屏幕
将最近登录的信息重定向到last.list,并且显示第一行信息到屏幕
last | tee last.list | cut -d ' ' -f1

将某些字符删除-tr
将data.txt文件中的空格删除,并显示
cat data.txt |tr -d " "

将order.txt中tab键(^I)替换为空格显示出来-col
cat order.txt | col -x |cat -A | more

将两个文件一起显示出来-paste
paste a.log b.log

执行多个命令-xargs
查询/etc/passwd文件的前三行的id属性
cut -d ":" -f1 /etc/passwd |head -n 3 |xargs -n 1 id
找到根目录下文件命含有test的文件,并全部列出来
find / -name "*test*" 2>/dev/null |xargs ls -l

利用正则进行grep查找
在command.list文件中查找以c开头t结尾中间为u或者a的字符
grep -n 'c[ua]t' command.list
在fruit.list中查找以非a开头的,含有p的字符
grep -n '[^a]p' fruit.list
在order.txt中查找以非小写字母开头的,含有order的字符
grep -n '[^a-z]order' order.txt
grep -n '[^[:lower:]]order' order.txt
在order.txt中查找只含数字的字符
grep -n '[0-9]' order.txt
grep -n '[[:digit:]]' order.txt
在order.txt中查找以order开头的行
grep -n '^order' order.txt
在order.txt中查找以小写字母开头的行
grep -n '^[a-z]' order.txt
grep -n '^[[:lower:]]' order.txt
在order.txt中查找不以英文字母开头的行
grep -n '^[^a-zA-Z]' order.txt
grep -n '^[^[:alpha:]]' order.txt
在order.txt中查找以order结尾的行
grep -n 'order$' order.txt
在order.txt中查找空行
grep -n '^$' order.txt
找到脚本order.sh中不含空行不以#开头的所有行
grep -v '^$' order.sh|grep -v '^#'
在order.txt中查找以o开头r结尾中间有三个字符的字符
grep -n 'o...r' order.txt
在order.txt中查找含有至少两个o的字符
grep -n 'ooo*' order.txt
在order.txt中查找o开头与o结尾的字符
grep -n 'o*o' order.txt
在order.txt中查找o开头并且r结尾,中间有任意字符的字符
grep -n 'o.*r' order.txt
在order.txt中查找至少含有一个数字的纯数字字符
grep -n '[0-9][0-9]*' order.txt
在order.txt中查找含有两个o的字符
grep -n 'o\{2\}' order.txt
在order.txt中查找g开头后面接2到5个o最后再接g的字符
grep -n 'go\{2,5\}g' order.txt
在order.txt中查找g开头后面接2个以上o最后再接g的字符
grep -n 'go\{2,}g' order.txt

posted @ 2022-08-08 20:58  漫途测开  阅读(48)  评论(0编辑  收藏  举报