Linux: Find Images greater than 500x500 then move to some folder (Find+Xargs+Mv)

StackOverflow https://stackoverflow.com/questions/22878469

  •  28-06-2023
  •  | 
  •  

سؤال

After running PhotoRec to recover photos after accidentally formatting my data partition, I'm left with 100s of directories with recovered images in them. Using Identity command, I'm able to find all photos of interest (larger than 500x500). But when I use xargs to push the out to a mv command, I get Permission Denied! I'm using sudo!

sudo find . -iname "*.jpg" -type f -exec identify -format '%w %h %i' '{}' \; | awk '{if ($1>300 || $2>300) print $3}' | xargs -I '{}' mv '{}' /home/simon/decent_size/

Output:

mv: cannot move ‘./recup_dir.3042/f848232448.jpg’ to ‘/home/simon/decent_size/f848232448.jpg’: Permission denied
mv: cannot move ‘./recup_dir.3042/f848239136.jpg’ to ‘/home/simon/decent_size/f848239136.jpg’: Permission denied
mv: cannot move ‘./recup_dir.571/f703451808.jpg’ to ‘/home/simon/decent_size/f703451808.jpg’: Permission denied
mv: cannot move ‘./recup_dir.2771/f835113704.jpg’ to ‘/home/simon/decent_size/f835113704.jpg’: Permission denied
...

Thank you for your help guys :)

هل كانت مفيدة؟

المحلول

That's because your find commands runs with root rights but not your xargs.

You want something like this:

sudo find . -iname "*.jpg" -type f -exec identify -format '%w %h %i' '{}' \; | awk '{if ($1>300 || $2>300) print $3}' | sudo xargs -I '{}' mv '{}' /home/simon/decent_size/

I didn't check the logic of your command, just fixed the 'permission denied' problem.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top