0
$ cat file_list
abc
def
ghi

I wanted to delete all files on the machine that are not in the file_list

How do I do that ?

Ankur Agarwal
  • 23,692
  • 41
  • 137
  • 208

1 Answers1

3

Assuming you're not going to delete all the files, here is a command to delete all files and directories under a given path only:

grep -ZzxFvf file_list <(find . -mindepth 1 -printf "%P\0") | xargs -0p rm -rf
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Hmm. `%P` prunes the leading `./`, so this'll match bare names only if the files found are directly in the current directory -- that may be what the OP wants, but it's hard to tell. – Charles Duffy Jan 27 '17 at 21:39