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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值