查找文件地址
find /home/ -name "test*" -type f # type 查找文件类型 -type d 为文件夹, -type f 为文件 >>> /home/learn/test.txt
查找当前目录下的文件
find . -name "test*" -type d
查找当前目录下指定文件并且最后编辑时间为30天以前或者一天内
find . -name "*01.txt" -type f -mtime +30 find . -name "*01.txt" -type f -mtime -1
查找并删除文件
find . -name "*01.txt" -type f -mtime -1 |xargs rm -rf {} \;
查找并拷贝文件
find . -name "test.*" -type f -mtime -1 -exec cp -r {} /home/abc \;
grep 命令
grep -n ‘2019-10-24 00:01:11‘ *.log
从文件内容查找匹配指定字符串的行:
$ grep "被查找的字符串" 文件名
例子:在当前目录里第一级文件夹中寻找包含指定字符串的 .in 文件
grep "thermcontact" /.in
从文件内容查找与正则表达式匹配的行:
$ grep –e "正则表达式" 文件名
查找时不区分大小写:
$ grep –i "被查找的字符串" 文件名
查找匹配的行数:
$ grep -c "被查找的字符串" 文件名
从文件内容查找不匹配指定字符串的行:
$ grep –v "被查找的字符串" 文件名
从根目录开始查找所有扩展名为 .log 的文本文件,并找出包含 "ERROR" 的行:
$ find / -type f -name "*.log" | xargs grep "ERROR"
例子:从当前目录开始查找所有扩展名为 .in 的文本文件,并找出包含 "thermcontact" 的行:
find . -name "*.in" | xargs grep "thermcontact"
查看指定程序的进程运行状态,并输出到指定文件中
ps aux | grep gsd > ps.log
打印显示输出的文件内容
cat ps.log
将文件内容安顺序排列输出到指定文件中
tr a-z A-Z < test.txt | sort > test01.txt