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

后端 未结 11 1053
野趣味
野趣味 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:47

    If it's just one file, one simple way is to move that file to /tmp or something, rm -Rf the directory and then move it back. You could alias this as a simple command.

    The other option is to do a find and then grep out what you don't want (using -v or directly using one of finds predicates) and then rming the remaining files.

    For a single file, I'd do the former. For anything more, I'd write something custom similar to what thkala said.

提交回复
热议问题