SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Beaumont's Avatar
    Join Date
    Mar 2005
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Bash command to copy only directory contents

    Can anyone tell me a simple way in Bash to copy all of the contents of a directory (and only the contents), including hidden files, into another, existing directory?

    E.g.

    Code:
    # I have this directory structure
    - directory_A
    --- existing_file
    -
    - directory_B
    --- some_file
    --- some_subdirectory
    --- .some_hidden_file
    
    # I want to end up with this
    
    - directory_A
    --- existing_file
    --- some_file
    --- some_subdirectory
    --- .some_hidden_file
    -
    - directory_B
    --- some_file
    --- some_subdirectory
    --- .some_hidden_file
    
    
    # I *don't* want this
    
    - directory_A
    --- existing_file
    --- directory_B
    ----- some_file
    ----- some_subdirectory
    ----- .some_hidden_file
    -
    - directory_B
    --- some_file
    --- some_subdirectory
    --- .some_hidden_file

    So far I've been stymied in finding a simple way to do this from the command prompt.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about a combination of the cpio and find commands.
    Code:
    find . -depth -print0 | cpio -0pdmv <target dir>
    I am not sure if this picks up hidden files but I am sure it could be altered to do so. I used this command to copy video/music files from one dir to another. Use man to understand the args. To use it as is you will need to be in the dir b and dir a will be your target.

    It has been a while since I used this command but I think I have given you the right one to not compress the files so please do check the man pages to make sure.

    Alternatives are the cp and dd commands.
    http://www.glasys.co.uk
    Noli Illegitimi Carborundum


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
  •