How do I safely delete all files with a specific extension (e.g. .bak
) from current directory and all subfolders using one command-line? Simply, I'm afraid to use rm
since I used it wrong once and now I need advice.
Ubuntu – How to recursively delete all files of a specific extension in the current directory
batchcommand linefilesrm
Best Answer
You don't even need to use
rm
in this case if you are afraid. Usefind
:But use it with precaution. Run first:
to see exactly which files you will remove.
Also, make sure that
-delete
is the last argument in your command. If you put it before the-name *.bak argument
, it will delete everything.See
man find
andman rm
for more info and see also this related question on SE: