删除linux目录下一半的文件,Linux面试题(一):删除一个目录下的所有文件,但保留一个指定文件...
假設這個目錄是/shnne/,里面有log1,log2,log3..log10 ?十個文件[root@shnne?shnne]#?touch?log{1..10}
[root@shnne?shnne]#?ls
log1??log10??log2??log3??log4??log5??log6??log7??log8??log9
方法一:find[root@shnne?shnne]#?ls
log1??log10??log2??log3??log4??log5??log6??log7??log8??log9
[root@shnne?shnne]#?find?/shnne?-type?f?!?-name?"log10"|xargs?rm?-f
[root@shnne?shnne]#?ls
log10
[root@shnne?shnne]#find?./?-type?f|grep?-v?"log10"|xargs?rm?-f
[root@shnne?shnne]#?find?/shnne?-type?f?!?-name?"log10"?-exec?rm?-f?{}?\;
[root@shnne?shnne]#?ls
log10
方法二:rsync[root@shnne?shnne]#?ls
log1??log10??log2??log3??log4??log5??log6??log7??log8??log9
[root@shnne?shnne]#?rsync?-az?--delete?--exclude?"log10"?/null/?/shnne/
[root@shnne?shnne]#?ls
log10
方法三:開啟bash的extglob功能(此功能的作用就是用rm !(*jpg)這樣的方式來刪除不包括號內文件的文件)[root@shnne?shnne]#?shopt?-s?extglob
[root@shnne?shnne]#?ls
log1??log10??log2??log3??log4??log5??log6??log7??log8??log9
[root@shnne?shnne]#?rm?-f?!(log10)
[root@shnne?shnne]#?ls
log10
方法四:[root@shnne?shnne]#rm?-f?`ls|grep?-v?"log10"`
總結
以上是生活随笔為你收集整理的删除linux目录下一半的文件,Linux面试题(一):删除一个目录下的所有文件,但保留一个指定文件...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab各个指令的含义,[MATLA
- 下一篇: java项目如何单元测试_大家java