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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)