Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

hope you can help me, I'm looking for a command to let me copy all files above 500kB in my directory one to directory 2..

Basically I have a lot of Images in directory1 and would like to copy all images larger than 500kB to my other folder directory2..

share|improve this question

migrated from Nov 26 '12 at 19:44

This question came from our site for professional and enthusiast programmers.

Do you want to copy, move, or make a link? You probably want to either move or make a (hard) link. Copying is rarely necessary. – William Pursell Nov 26 '12 at 19:34
Well, I want to copy, because thats what i want. My folder of images is made by foremost, so I want to keep the collection as a whole untill later... – Qw_freak Nov 26 '12 at 22:08
I notice that I am getting some votes down, why is this? Should i have elaborated that I had tried various things with xargs, which did'nt work before asking my question? – Qw_freak Nov 27 '12 at 7:38
up vote 3 down vote accepted

You can use find thus:

find directory1 -type f -size +500k -exec cp -nv {} directory2/ \;
  • -v : verbose copy (you see what's copying)
  • -n : noclobber (might not be available to your cp version): do not overwrite an existing file (just in case).
share|improve this answer
Thanks man, it really helped, I had like a million images ranging from 1kB to 7mB, and 99% of those where >500kB... They where collected by foremost because i acidently deleted an image folder... – Qw_freak Nov 26 '12 at 22:10
Why the Backslash semicolon in the end? – Qw_freak Nov 27 '12 at 7:38
@Qw_freak because for bash, a semicolon is a separation character, so if not escaped, it would not be sent to find. But find needs to have a semicolon to know where the -exec option ends. We must hence escape it. – gniourf_gniourf Nov 27 '12 at 9:49

This should do it:

find directory1 -type f -size +500k -exec cp {} directory2 \;
share|improve this answer

You must log in to answer this question.

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