构建一个关于在 Linux 中查找文件、监控以及与此相关的所有内容的“备忘单”。这是其中一些
递归查找包含特定文本的文件
grep -rn "pattern" /path/to/dir
# include only certain files
grep -rn "pattern" --include="*.js" --exclude="*node_modules/*" --exclude="*.min.js*" /path/to/dir
添加-w以匹配整个单词而不是部分
添加-i不区分大小写的搜索
如何在 Linux 中查找文件
find /path/to/dir -name "*.js"
# execute a command on those files
# "{} \;" just means the command ends
find /path/to/dir -name "*.js" -exec rm -f {} \;
find /path/to/dir -name "*.js" -exec chmod 700 {} \;
该find命令非常强大,可以执行其他操作,例如:
查找具有特定权限的文件 find . -type f -perm 0664
查找属于特定用户的文件 find . -user joe
查找 N 天前修改的文件 find . -mtime 50
查找给定大小的文件 find . -size 50M
查找您的进程是否正在运行
ps aux | grep postgres
查找开放端口和拥有它们的进程
lsof -i
lsof -i | grep apache
# list processes using tcp port 80
lsof -i tcp:80
lsof是一个列出打开文件的命令。单独运行它会列出活动进程中所有打开的文件。添加-i不带选项会列出所有具有网络文件的内容。添加一个选项
查找您的内部 IP 地址
/sbin/ifconfig
网友评论