For something a bit fancier than answering yes or no to each file, you could use iselect
for interactive ncurses-based selection. e.g.
iselect -a -m < list.txt | xargs -d '\n' -r echo rm
or to allow selection of files in the current dir:
find . -maxdepth 1 -type f | iselect -a -m | xargs -d '\n' -r echo rm
That will display a full-screen (full-terminal) ncurses-based listing, where files can be selected and de-selected at will by pressing SPACE. press ENTER to accept your selections (selected entries will be printed on stdout), or q
to quit (nothing printed to stdout). press h
for help.
Note the echo rm
- i've written it like that for testing. change it to just rm
once you're confident you understand what it's doing.
Also note that xargs
is being used here with \n
as the input separator. This will not work if any of the filenames have linefeed characters in them. For that matter, the iselect
won't work properly either - it expects one item per line - u nfortunately, iselect
does not have an option for null-terminated input or output.
iselect
is packaged for debian, probably ubuntu and other distros too. home page is at http://www.ossp.org/pkg/tool/iselect/