I'm trying to pipe some files from the find command to the interactive remove command, so that I can double check the files I'm removing, but I've run into some trouble.
find -name '#*#' -print0 | xargs -0 rm -i
I thought the above would work, but instead I just get a string of "rm: remove regular file ./some/path/#someFile.js#? rm: remove regular file ./another/path/#anotherFile#?..."
Can someone explain to me what's exactly is happening, and what I can do to get my desired results? Thanks.
If you want to use xargs command to delete these files just pipe it to xargs command with rm function as its argument. In the above case, xargs command will construct separate rm statements for each file name passed to it by the result of find command. That's it.
You can do this by using exec
option with find
. Use the command
find . -name '#*#' -exec rm -i {} \;
xargs
will not work (unless you use options such as -o
or -p
) because it uses stdin
to build commands. Since stdin
is already in use, you cannot input the response for query with rm
.
you can use this simple command to solve your problem.
find . -name '#*#' -delete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With