刪除一個目錄下的全部文件,但保留一個指定文件

例題:刪除一個目錄下的全部文件,但保留一個指定文件。
           
           解答:
             假設這個目錄是/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
ide

             file5          it




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

   

未完待續…file

                                                                                                                               ( 原創~oldboy培訓)方法

相關文章
相關標籤/搜索