Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 06-05-2008, 09:27 PM   #1
LQ Newbie
Registered: Jun 2007
Location: Ontario, Canada
Distribution: Ubuntu, Debian, CentOS
Posts: 28

Rep: Reputation: 16
Help me figure out proper "find" usage for this situation

I need to be able to copy all files/subdirectories from one particular directory on one drive to another drive... but only files / directories that do not already exist on dest drive or are older on dest drive... also exclude anything larger than 2gigs in size. Basically, like executing "cp -au /home/somedir /mnt/usb" but with the 2gig exception rule.

I know this is do-able with a well crafted "find" command but I am not knowledgable enough to work it out.

Anybody help?
Old 06-05-2008, 11:11 PM   #2
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
Well the size problem is the easy bit. Just use the '-size' predicate, with a -2G argument. As for the copying, you can't do a 'cp -a', since that'll recursively copy everything each time (including the +2G files). I think the following should work:
find /source/path -size -2G -exec \
  cp --parents -u {} /targetpath/`dirname {}` \;
It'll give a lot of errors about not being able to copy directories, but it works anyway (cp can't directly copy just a directory, but it'll create required ones if you specify --parent).
If they're just normal files, you could add a '-type f' to silence the errors (by telling 'find' to not find directories, symlinks etc).

Hope this helps.
Old 06-05-2008, 11:49 PM   #3
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Have you thought about using rsync instead of cp? That should automatically do everything but the 2gb bit. Use find as above for that.
Old 06-06-2008, 08:48 AM   #4
LQ Newbie
Registered: Jun 2007
Location: Ontario, Canada
Distribution: Ubuntu, Debian, CentOS
Posts: 28

Original Poster
Rep: Reputation: 16
Thanks for the help... works... but will look into using rsync as well.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Usage of "k size" option in "tar" ?? kcarun Solaris / OpenSolaris 4 08-20-2007 02:59 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Where to find a "nice" Howto" for modem setup and use for IPS usage xerxesii Linux - Hardware 2 03-27-2007 12:21 AM
Why was "lazy unmount" required in this situation? haertig Linux - Software 3 03-04-2006 01:38 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration