脚本示例:
使用shell批量删除10天内没访问过的文件
find命令有一个参数可以避免特殊字符对后面执行的命令产生影响
命令变成这样:
一般来说不会有什么问题,但如果每个文件路径都特别深,那么会导致参数很多,命令行很长。
比如会看到如下提示:
那可以让xargs一次处理一条试试:
-l1是一次处理一个
-t是处理之前打印出命令,适合调试或者欣赏观看用
原创内容如转载请注明:来自 阿权的书房
find . -type f -atime +10 | xargs rm -f
使用shell批量删除10天内没访问过的文件
find命令有一个参数可以避免特殊字符对后面执行的命令产生影响
-print0
True; print the full file name on the standard output, followed by a null character (instead of the new-
line character that ‘-print’ uses). This allows file names that contain newlines or other types of
white space to be correctly interpreted by programs that process the find output. This option corre-
sponds to the ‘-0’ option of xargs.
True; print the full file name on the standard output, followed by a null character (instead of the new-
line character that ‘-print’ uses). This allows file names that contain newlines or other types of
white space to be correctly interpreted by programs that process the find output. This option corre-
sponds to the ‘-0’ option of xargs.
命令变成这样:
find . -type f -atime +10 -print0 | xargs -0 rm -f
一般来说不会有什么问题,但如果每个文件路径都特别深,那么会导致参数很多,命令行很长。
比如会看到如下提示:
xargs: argument line too long
那可以让xargs一次处理一条试试:
find . -type f -atime +10 -print0 | xargs -0 -l1 -t rm -f
-l1是一次处理一个
-t是处理之前打印出命令,适合调试或者欣赏观看用
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
从文本读取数据要注意特殊字符
转:Linux内核高危漏洞1 --简单防范
