美文网首页
linux常用指令汇总(持续更新)

linux常用指令汇总(持续更新)

作者: 至爱雅鸿_e631 | 来源:发表于2020-05-29 09:52 被阅读0次
  • 某个字符串被哪些文件包含
find /opt/ylbzj/renkoudata/ -name  "cbry_child*.txt"|xargs grep 130982199906081155
  • 输出当前目录文件夹大小
du -h --max-depth=1  2>/dev/null  | sort -hr 
  • 检查端口是否占用
netstat -ntlp|grep 8823
  • 检查是否安装了epel
rpm -qa|grep epel
  • 替换文件中的字符
简单替换
sed -i 's/原字符串/新字符串/g' /home/1.txt
批量替换(grep '需要替换的字符' -rl 路径|xargs sed -i 's/原始字符/新字符/g')
grep '123456:8089' -rl . |xargs sed -i 's/123456/111.63.208.5/g'
打印passwd的3到10行 
sed -n '3,10'p passwd
打印passwd 中包含 ‘root’ 的行 
sed -n '/root/'p passwd
删除passwd 的15行以及以后所有行 
sed '15,$'d  passwd
删除passwd中包含 ‘bash’ 的行 
sed '/bash/'d passwd
替换passwd 中 ‘root’ 为 ‘toor’ 
sed 's/root/toor/g' passwd
替换passwd中 ‘/sbin/nologin’ 为 ‘/bin/login’ 
sed 's#sbin/nologin#bin/login#g' passwd
删除passwd中5到10行中所有的数字 
sed '5,10s/[0-9]//g' passwd
删除passwd 中所有特殊字符(除了数字以及大小写字母) 
sed 's/[^0-9a-zA-Z]//g' passwd
把passwd中第一个单词和最后一个单词调换位置 
sed 's/\(^[a-zA-Z][a-zA-Z]*\)\([^a-zA-Z].*\)\([^a-zA-Z]\)\([a-zA-Z][a-zA-Z]*$\)/\4\2\3\1/' passwd
把passwd中出现的第一个数字和最后一个单词替换位置 
sed 's#\([^0-9][^0-9]*\)\([0-9][0-9]*\)\([^0-9].*\)\([^a-zA-Z]\)\([a-zA-Z][a-zA-Z]*$\)#\1\5\3\4\2#' passwd
把passwd 中第一个数字移动到行末尾 
sed 's#\([^0-9][^0-9]*\)\([0-9][0-9]*\)\([^0-9].*$\)#\1\3\2#' passwd
在passwd 20行到末行最前面加 ‘aaa:’ 
sed 's/^.*$/&aaa/' passwd
  • 查看文件行数
wc -l 文件名
  • 网络抓包命令 抓tcp的80端口输出到 captcha22.cap
tcpdump -tttt -s0 -X -vv tcp port 80 -w captcha22.cap
  • 从当前目录查找包含特定内容的文件
## 不区分大小写列出内容和文件
find .|xargs grep -ri '特定内容'
## 只列出文件
find .|xargs grep -ril '特定内容'
  • 查找文件
## 查找文件和文件夹 / 可替换为特定目录 如:/opt
find / -name 'filename'
## 查找文件夹
find / -name 'path' -type d
## 查找文件
find / -name 'fileName' -type f

相关文章

网友评论

      本文标题:linux常用指令汇总(持续更新)

      本文链接:https://www.haomeiwen.com/subject/qiedyhtx.html