Wednesday, 18 November 2015

One Liner to delete all the files with names present in the txt file using xargs bash

There is simple one liner, that will delete all the files, you listed in a text file containing their names.

For Ex:

Create a file with name "filenames" contains the list of all the files  that you want to delete, then execute below command on the terminal.

xargs -a filenames -d'\n' rm

xargs -  to build and execute command lines from
-a - to use for providing input from text file instead of stdin
filenames - the file you just created
-d - delimiter
rm - command to pass the list

You can also use "-i" with rm for interactive mode.