How do you do a dry run of rm to see what files will be deleted?
Say you want to run:
rm *.txt
You can just run:
echo rm *.txt
or even just:
echo *.txt
to see what files rm
would delete, because it's the shell expanding the *.txt
, not rm
.
The only time this won't help you is for rm -r
.
If you want to remove files and directories recursively, then you could use find
instead of rm -r
, e.g.
find . -name "*.txt" -print
then if it does what you want, change the -print
to -delete
:
find . -name "*.txt" -delete
You can say:
rm -i
to run it in interactive mode, so rm
will prompt you to confirm whether each file should be deleted. You could just answer no to each file to see which ones would be affected.
You can use ls
to list all the files that will be removed by rm
:
ls ../path/*.txt
If you need to list to view the files that will be deleted with a recursive rm
, then use the -R
flag with ls
:
ls -R ../path/*.txt