Is there way to tell the bash find
command to output what it is doing (verbose mode)?
For example for the command:
find /media/1Tb/videos -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
to output:
Found /media/1Tb/videos/102, executing rm -rf /media/1Tb/videos/102
...
You could concoct something with
-printf
, but the easiest is just to tack on-print
on the end. This will show what was successfully deleted.How about just using
rm -vf
for verbose rm output.An alternative is to let the commands be executed by
sh -x
:There is also
find -D xxxx
that could help in some cases.Below are two examples of
find -D search
:Using RHEL 6.3 (
find
v4.4):Using Cygwin 1.7 (
find
4.5):@hlovdav's answer was enough for me but I did some modifications for my own use
Explanation
pattern
null
separated, important if you have filenames with spaces or unusual characters in itxargs
readnull
separated, set each record placeholder to%%
This also ensures every time it uses only one argumentbash
command, one-liner, anything goes inside, must be single quoted'
--
meaning anything I do after this is notxargs
orbash
options but positional parameters to my one-liner scriptbash
script, you can access%%
as$1
, positional argument No #1Note: You can change
%%
with anything, just make sure you don't need to use it for anything other than a placeholder. Using dollar$
or@
might not be good, unless it's double@
like@@
.