Removing files with rm with find and xargs

When i do

rm file.txt 

or

 rm *.txt 

Each file is offered to me, since I did not specify the -f option to rm .

But when I do this:

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

files are deleted without confirmation.

What are the logic behind this? Can I find the reason in some kind of documentation? I can not explain why this would be so.

+5
source share
1 answer

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

 rm file.txt 

or

 rm *.txt 

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

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

rm is passed as a simple string argument to xargs and is later called by xargs without shell expansion substitution. Your nickname is probably defined in ~ / .bashrc if you want to remove it.

+5
source

Source: https://habr.com/ru/post/1265536/


All Articles