Page 1 of 5 123 ... LastLast
Results 1 to 10 of 43

Thread: recreating folders

  1. #1
    Join Date
    Nov 2013
    Beans
    52

    recreating folders

    Hi,

    I have about 570 folders and sub-folders on my disk.

    I need to create the exact named copy of folders and sub folders, I would also need to copy over all files within the folders and subfolders from origin to destination drive, meaning exclude the files that have the .xyz extension. The reason for this is that I have some corrupted files which I do not want to transfer over. It is really important that I get this solved as soon as possible!

    Is there a command that can do this quickly?

    kind regards
    Last edited by kingcobraa; January 5th, 2014 at 06:08 PM.

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: recreating folders

    Yes, there is. I don't have it myself at this instance, but either rsync or a find -exec mkdir -p command is where I'd start.

    I didn't test this, but ....
    Code:
    find $TOP_DIRECTORY -type d -exec mkdir -p {} \;
    ought to do it. Run it from the directory where you want all the subdirs to be created. Don't expect groups, owners and special permissions to be retained. Might want to include symlinks (or NOT) and other special ACLs too. Don't know your situation.

    That should get you started on a workable path.

    Update ... that find command may need to be swapped around ... that is run from the source directory to get relative dirs.

    Code:
    find . -type d -exec mkdir -p $TARGET_DIR/{} \;
    Does that make sense?
    Last edited by TheFu; January 5th, 2014 at 06:05 PM. Reason: added update.

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: recreating folders

    There's a bunch of hairy-chested ways to do this, however I *think* the easiest way is using rsync, with filters to exclude everything and include directories e.g.

    Code:
    rsync -av -f'+ */' -f'- *' /path/to/source/dir/ /path/to/target/dir/
    see for example http://www.cyberciti.biz/faq/unix-li...s-trees-rsync/

    e.g. to duplicate the directory structure of your Documents directory

    Code:
    rsync -av -f'+ */' -f'- *' ~/Documents/ ~/Documents2
    (rsync creates the Documents2 directory for you - no need to mkdir first)
    Last edited by steeldriver; January 5th, 2014 at 06:12 PM.

  4. #4
    Join Date
    Nov 2013
    Beans
    52

    Re: recreating folders

    Hi, please see my edit.

  5. #5
    Join Date
    Nov 2013
    Beans
    52

    Re: recreating folders

    hi i tried the commands and get errorsrsync -av -f'+ */' -f'- *' /home/downloads/All workouts/ /home/desktop/all workouts/
    sending incremental file list
    rsync: change_dir "/home/downloads" failed: No such file or directory (2)
    rsync: link_stat "/home/desktop/all" failed: No such file or directory (2)

    sent 2074939 bytes received 1729 bytes 1384445.33 bytes/sec
    total size is 0 speedup is 0.00
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]

  6. #6
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: recreating folders

    Quote Originally Posted by kingcobraa View Post
    Hi, please see my edit.
    Copying all files is exactly what rsync is for. Use the --exclude option to prevent specific file patterns.

    rsync -avz --exclude '.xyz' SOURCE TARGET

    man rsync explains more. Your Linux system already has most answers preloaded.

  7. #7
    Join Date
    Apr 2012
    Beans
    7,256

    Re: recreating folders

    ... and put the SOURCE and TARGET directory paths in quotes since you have spaces in them

  8. #8
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: recreating folders

    Quote Originally Posted by steeldriver View Post
    ... and put the SOURCE and TARGET directory paths in quotes since you have spaces in them
    Most definitely correct. Thanks SD!

  9. #9
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: recreating folders

    If you look at all the options rsync has it can be very confusing as it has so many. I think you need exclude or filter option to restrict what you copy. I use --exclude but with a file with several folders listed in the file that I do not want to copy.

    I use a script for backup but like to list the options I may use, just to remmember what I am doing. Best to use the n option for testing until you are sure you have correct settings.

    If a one time thing you do not need script just the one line rsync command.
    #!/bin/bash
    # backup script - mybackup.sh
    # a - archive, retain file settings equals -rlptgoD (no -H,-A,-X)
    # r - recursive / subdirectories
    # u - update, only newer
    # v - verbose
    # P - keep partial files and report progress
    # -l, --links copy symlinks as symlinks
    # -i, --itemize-changes
    # -t, --times preserve modification times
    # --exclude option to prevent copying things

    rsync -aruvlP /home/fred/Notebooks /mnt/data/Notebooks
    rsync -aurvlP --exclude-from=mybackup_excludes.lst /home /mnt/backup
    I do not now use this as my excludes.lst became so long as not to easily be on one line, so I use file like above.
    #rsync -aurvlP --exclude '.thumbnails' /home /mnt/backup

    Above are in script, so i do not need sudo, but if just running the one command line, you would need sudo.

    See man rsync for more info.
    Last edited by oldfred; January 5th, 2014 at 06:41 PM.
    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  10. #10
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    5,739

    Re: recreating folders

    The structure of the file system is not clear here and really has a bearing on the solution - where are the 570 folders in relation to one another? Are they scattered all about your home folder in various places, or subfolders of another? In any case, the option --exclude=*.xyz will omit files with that extension from being copied.

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •