Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I need to move all files from a directory, discarding the directory structure.

Unfortunately, some files have the same file name (Thumbnails). I'm looking for smth. like this:

find /tmp/dirtree -type f -exec mv -i {} . \;

How can I prevent the overwriting of larger files during the process?

share|improve this question
up vote 2 down vote accepted

Create the Perl script:

use File::Copy;
$file = shift;
($name = $file) =~ s#.*/##;
if (-f $name and -s $file < -s $name) {
     warn "$name not moved";
} else {
     move($file, $name);

Then, change the line to

find /tmp/dirtree -type f -exec perl {} \;
share|improve this answer
Simple stupid solution means KISS! Please edit your post and add the perl parameter after -exec. I got curious issues without that. Thank you. – mate64 Oct 26 '12 at 13:35
@msec: Updated. – choroba Oct 26 '12 at 15:08
This would probably get more upvotes if you explained what it did. At least from me. In the OP's question, it looks like he is moving the files to the current directory "." but I can't tell where you're moving it. – Buttle Butkus Apr 7 at 3:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.