I did a web seach for "linux run find on find" but it produced no relevant results. I want to build list of files by find and then run find again on that list.
After fixing some "silly" mistakes I guess coming from little experience with command line work, final command is:
find "path1" -size 0 -printf "%f\0" | xargs -0 --max-args=1 --verbose find "path2" -exec ls -l {} \\\; -name
As --verbose
, I see commands run as
find path -exec ls -l {} \; -name foundfilename
and output missing argument to exec
.
If I run resulting command build by xargs
directly (adding double quotes as for some reason xargs --verbose output misses, but apparently uses in practice as find does not have issues with path that includes spaces:
find "path" -exec ls -l {} \; -name foundfilename
and output looks like all files in path
.
- Why different result from xargs and direct
find
run? - Looks like
-exec
cannot precede-name
, is it correct? - Finally to the point: How to properly run
find
on results on anotherfind
?
System: Linux Mint 19.2
Added after comment to clarify 2nd question:
If I run
find "path" -name foundfilename -exec ls -l {} \;
I got output of several files found and listed by ls
as expected, that is to the 2nd question.
I did test setup of two files named 1
and 2
in /media/ramdrive
.
marina@tpx:~$ find /media/ramdrive -exec ls {} \; -name 1
1 2
/media/ramdrive/2
/media/ramdrive/1
marina@tpx:~$ find /media/ramdrive -name 1 -exec ls {} \;
/media/ramdrive/1
Man on find:
-exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of
;' is encountered. The string
{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `') or quoted to protect them from expansion by the shell. See the EXAMPLES sec‐ tion for examples of the use of the -exec option. The specified command is run once for each matched file. The command is exe‐ cuted in the starting directory. There are unavoidable secu‐ rity problems surrounding use of the -exec action; you should use the -execdir option instead.
I don't see why -exec
cannot precede options for matching.
Actually I don't understand meaning of "everywhere it occurs in the arguments to the command, not just in arguments where it is alone".
ADDED TWO:
I though I found a solution by:
find "path1" -size 0 -printf "%f\0" | xargs -0 --max-args=1 --verbose find "path2" -name | xargs ls -l
but default print from find does not quote results, so fails for path with spaces. If there utility to add quotes?