Using find - Deleting all files/directories (in Linux ) except any one

后端 未结 11 1058
野趣味
野趣味 2021-02-02 15:12

If we want to delete all files and directories we use, rm -rf *.

But what if i want all files and directories be deleted at a shot, except one particular fi

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 16:10

    I see a lot of longwinded means here, that work, but with a/ b/ c/ d/ e/

     rm -rf *.* !(b*) 
    

    this removes everything except directory b/ and its contents (assuming your file is in b/. Then just cd b/ and

    rm -rf *.* !(filename) 
    

    to remove everything else, but the file (named "filename") that you want to keep.

提交回复
热议问题