I would like to search for all the nohup.out
in my mounted filesystems, and delete them.
-
There are some directories and files whose filenames contain space, so I think of
xargs -0
. -
To be safe, I would like to interactively delete them, i.e. be asked if I really want to delete them. So I think of
rm -i
andxargs -p
-
I also would like to delete each found file seperately, so I think of
xargs -n 1
.
But the following command doesn't work in the way I hope.
locate -i nohup.out | xargs -0 -n 1 -p rm -i
It doesn't prompt each file to be removed and ask for my permission.
I wonder why and what command works as I hope?
By the way my xargs version is xargs (GNU findutils) 4.4.2. Can it be the reason?
Best Answer
Of course if you are using
xargs -0
then you must match that withlocate -0
.xargs
should read input from/dev/tty
when prompting you. It works that way so that there is no conflict between the use ofxargs
's stdin for reading arguments fromlocate
and reading responses for the-p
option.However, you are using
xargs
to runrm -i
. Therm -i
command also wants to read your input, which it will read from stdin. Hence it eats up part ofxargs
's input and things don't work how you expect.If you are using Bash, this is one option:
However, you can also do everything in find:
Change ';' to '+' to delete more than one file at a time. This requirement and the various ways you can solve this problem are explained in the Texinfo manual for findutils.