Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 down vote accepted

Create the mymv.pl Perl script:

#!/usr/bin/perl
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 mymv.pl {} \;
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. –  cept0 Oct 26 '12 at 13:35
    
@msec: Updated. –  choroba Oct 26 '12 at 15:08

Your Answer

 
discard

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.