您的位置:首页 > 其它

删除一个目录下的所有文件,但保留一个指定文件

2017-09-02 10:21 381 查看
例题:删除一个目录下的所有文件,但保留一个指定文件。

解答:
假设这个目录是/xx/,里面有file1,file2,file3,file4,file5 五个文件
[root@oldboy xx]# touch file{1..5}
[root@oldboy xx]# ls
file1 file2 file3 file4 file5

方法一: find
[root@oldboy xx]# ls
file1 file2 file3 file4 file5
[root@oldboy xx]# find /xx -type f ! -name "file5"|xargs rm -f
[root@oldboy xx]# ls

file5

或 [root@oldboy xx]# find /xx -type f ! -name "file5" -exec rm -f {} \;
[root@oldboy xx]# ls
file5

未完待续…
( 原创~oldboy培训)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  find 的企业案例
相关文章推荐