Bash script to remove all files and directories except specific ones

前端 未结 5 893
无人及你
无人及你 2021-01-04 17:12

I am trying to write a very simple Bash shell script that will cd in a specific directory, it will remove all files and directories except some few selected ones and then cd

5条回答
  •  感情败类
    2021-01-04 18:16

    Try below:

    for i in `ls | grep -v "file1\|file2\|file3"` ; do rm -rf $i; done
    

    Good Luck!

提交回复
热议问题