Removing files with rm using find and xargs

You have an alias set for the rm command to 'rm -i'. Therefore if you invoke the command directly as in

rm file.txt

or

rm *.txt

the alias will be expanded. If you will call it with xargs as in

find . -type f -name '*.txt' | xargs rm

The rm is passed as a simple string argument to xargs and is later invoked by xargs without alias substitution of the shell. You alias is probably defined in ~/.bashrc, in case you want to remove it.


you can use this simple command to solve your problem

find . -type f -name '*.txt' -delete

Depending on your version of xargs you may have the --no-run-if-empty GNU extension option available to you:

find . -type f -name '*.txt' | xargs  --no-run-if-empty  rm -rf

Tags:

Linux

Xargs

Rm