Why | not working with search?

Why is the following command directed to delete recursively all .svn folders

find . -name ".svn" | rm -rfv 

does not work?

I know that the find provides the -exec option to solve this problem, but I just want to understand what is going on there.

+4
source share
5 answers

In your example, the results from find are passed to rm STDIN. rm does not expect its arguments in STDIN.

Here is an example of how input redirection works.

+12
source

rm does not read file names from standard input, so any data transferred to it is ignored.

The only thing it uses standard input for is checking if it is a terminal, so it can determine if it should be requested.

+2
source

This does not work because rm does not accept the list of file names in the standard input stream.

For reference, the safest way to handle this is with directories that may contain spaces:

 find . -name .svn -exec rm -frv {} \; 

Or if you shoot at speed:

 find . -name .svn -print0 | xargs -0 rm -frv 
+1
source

find a job with | (for example, find ~ -name .svn | grep "a" ), but the problem is rm

+1
source

This question is similar to this other answer. Hope this helps.

How to turn on the handset | in my linux find -exec command?

0
source

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


All Articles