0

I have a Master folder with following subfolders:

  • f1
  • f2

with jpeg/jpg files in each subfolder. I do find . -maxdepth 2 -type f -iname '*.jp*g' and getting output:

  • ./f1/IM_48902.jpg
  • ./f1/IM_48903.jpg
  • ./f2/IM_48900.jpg
  • ./f2/IM_48904.jpg

How I can exclude '/f1' and '/f2' from output and get such output?

  • ./IM_48902.jpg
  • ./IM_48903.jpg
  • ./IM_48900.jpg
  • ./IM_48904.jpg

[UPD] my full script is find . -maxdepth 2 -type f -iname '.jpg' ! -path "/excluded/" -print0 | xargs -I{} -0 -n1 -P3 sh -c 'exiv2 -q -K Xmp.dc.creator -K Xmp.photoshop.Credit -Pv "$1" > "/Users/adm/Desktop/$1.out"' -- {}

2

2 Answers 2

0

With GNU find, use the -printf action. See man find

find . -maxdepth 2 -type f -iname '*.jp*g' -printf "%f\n"
2
  • I don't use GNU, my full script is find . -maxdepth 2 -type f -iname '.jpg' ! -path "/excluded/" -print0 | xargs -I{} -0 -n1 -P3 sh -c 'exiv2 -q -K Xmp.dc.creator -K Xmp.photoshop.Credit -Pv "$1" > "/Users/adm/Desktop/$1.out"' -- {}. I've tried to use | sed 's|^./||' but it's not working with -print0
    – K. S.
    Commented Mar 12, 2023 at 15:41
  • I've checked your answer on server and it's working good! locally I have macos and it's not working.
    – K. S.
    Commented Mar 12, 2023 at 18:40
0

In general, you can run the output of find . -maxdepth 2 -type f -iname '*.jp*g' through e.g. sed:

% mkdir f1 f2; touch f1/abc f2/def
% find . -type f |sed -e 's:.*/:./:' 
./def
./abc

But if you need to do that for NUL-separated "lines", you need a sed that supports that, e.g. sed -z with GNU sed.

Alternatively, you could remove the prefix within the shell command later with the ${var##pattern} expansion which removes the longest matching prefix from the value.

$ find . -type f -print0 | xargs -I{} -0 sh -c 'echo "./${1##*/}"' -- {}
./def
./abc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .