1

Is it possible to print find output paths in such a way that you can copy and paste them, they will already be properly escaped so that you can execute commands on that path? Usually I have to put quotes around them.

Example.

$ find -iname "*Resume 2004*doc~"
./Career/No Longer Needed/Microsoft Resume 2004.doc
$ rm ./Career/No Longer Needed/Microsoft Resume 2004.doc
ERROR: No such file: ./Career/No
$ rm "./Career/No Longer Needed/Microsoft Resume 2004.doc"

Note: I do not want to execute the rm "automatically" via -exec or xargs. I know how to do that.

slhck
  • 235,242

2 Answers2

0

find have an -exec argument.

If you are trying to delete find output, just use this command:

find -iname "*Resume 2004*doc~" -exec rm -f {} \;
jherran
  • 1,949
0

The rm command doesn't work since your filename includes white spaces, so for this reason you either have to quote your file, or you can use backslash without quoting, like that:

rm ./Career/No\ Longer\ Needed/Microsoft\ Resume\ 2004.doc

So, you cannot really print the path and delete it by copy pasting because you either need to add quotes or backslashes, but what you can do is to print the inode of the file as well with the find command and delete it by using the inode number like that:

find . -type f -name "*Resume 2004*doc~" -printf '%p %i\n'

and you get back its inode lets say 1234567 and you delete it like that:

find . -inum 1234567 -exec rm -fi {} \;