The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Copy recursively, omit one subdirectory

    Discussion in 'Linux Compatibility and Software' started by system_159, May 22, 2008.

  1. system_159

    system_159 Notebook Deity

    Reputations:
    363
    Messages:
    794
    Likes Received:
    0
    Trophy Points:
    30
    Posted this at linuxforums.org, figured I'd cross post it here since you guys tend to answer quicker.

    I have a directory on a text only machine that is 17GB that I have to transfer over to another machine. Unfortunately all I have to do it with is a 2GB flash drive. There's one subdirectory inside this directory that is 16GB, so if I could copy all the files/directories except this one it'd make it a lot easier(I could then go through and get only what I needed from it.

    So if I've got a directory named "top" and it has ~100 files and ~20 sub directories, one of named "data" that is 16GB. How would I go about copying everything but "data"?

    Kind of like this:
    Code:
    cp -r top -omit /data /mnt/usb/destination
    
    if that makes any sense.
    Thanks!
     
  2. wearetheborg

    wearetheborg Notebook Virtuoso

    Reputations:
    1,282
    Messages:
    3,122
    Likes Received:
    0
    Trophy Points:
    105
    Why not just move the huge directory outside, and then copy the original directory
    Something like:
    Code:
    mv top/data .
    cp -R top mnt/usb/destination
    
     
  3. system_159

    system_159 Notebook Deity

    Reputations:
    363
    Messages:
    794
    Likes Received:
    0
    Trophy Points:
    30
    The directories in question are in active use, so I need to keep file structure in place.

    I went ahead and copied all the files via cp *.*, then copied each directory separately. It was a bit of a pain but it's done with.

    I'm still really interested to know if there's a somewhat simple way of doing this, though.
     
  4. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    I haven't tested this, but I'd probably do something with a bash one-liner (assuming there no filenames or directories inside top/ with spaces):

    Code:
    for f in $(find top -maxdepth 1 -name '*'|grep -v '/data');
       do echo cp -av "$f" /mnt/usb/destination/;
    done
    The 'echo' is there to see what will happen without it actually doing the copying, once I am happy the line resubmitted without the 'echo'.
     
  5. wearetheborg

    wearetheborg Notebook Virtuoso

    Reputations:
    1,282
    Messages:
    3,122
    Likes Received:
    0
    Trophy Points:
    105
    If you are not do know shell scripting, then the following (ugly soln) will work:
    Code:
    cd /mnt/usb/destination
    mkdir data
    chmod 000 data
    cp  -R xyz/top/* .
    chmod 700 data
    rmdir data
    
    The copy command will say that permission was denied to copy the contents of data; and it will take a long time (as it will try to copy all 16GB of top, failing for each file).
    But it will work :D

    EDIT: the following might be better:
    Create a file called data in /mnt/usb/destination, then do the recursive copy. Copy will say it cant overwrite a file with a directory, so it wont access the 16GB of data