Search code examples
bashstdinpipelinerm

Why won't rm remove files passed in from find or sed?


I want to pipeline the below commands but the last cmd "rm -rf"is not working i.e. Nothing deleted :

find /home/mba/Desktop/ -type d -name "logs" | sed 's/$/\/\*/' | rm -rf

No error is returned.


Solution

  • The rm command doesn't take filenames from standard input. If you want to pipe from sed to rm, you can use xargs. For example:

    find /home/mba/Desktop/ -type d -name "logs" | sed 's/$/\/\*/' | xargs rm -rf