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

后端 未结 11 1387
野趣味
野趣味 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 15:56

    In bash you have the !() glob operator, which inverts the matched pattern. So to delete everything except the file my_file_name.txt, try this:

    shopt -s extglob
    rm -f !(my_file_name.txt)
    

    See this article for more details: http://karper.wordpress.com/2010/11/17/deleting-all-files-in-a-directory-with-exceptions/

提交回复
热议问题