Results 1 to 4 of 4

Thread: Copying file to destination: how to preserve directory hierarchy?

  1. #1
    Join Date
    Sep 2006
    Location
    Central Europe
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Copying file to destination: how to preserve directory hierarchy?

    I have a text file containing a list of files like:

    Code:
    /etc/modprobe.d/blacklist.conf
    /etc/rsyslog.d/50-default.conf
    /etc/ufw/ufw.conf
    /lib/bootchart/gather
    /lib/resolvconf/list-records
    /usr/lib/php5/20060613+lfs/gd.so
    /usr/lib/php5/20060613+lfs/pdo.so
    How would I copy them to a target directory while keeping the directory hierarchy intact?

    I can't do
    Code:
    for file in list: cp file target
    because that would put all files in the target directory.

    I also cannot do
    Code:
    for file in list: cp file target/file
    because direcotries like /etc or /usr/lib/php5 don't exist.

    Any help is appreciated, TIA!
    The Power User’s Guide to Unity
    Questions about Ubuntu? Ask them at askubuntu.com!

  2. #2
    Join Date
    May 2006
    Beans
    1,790

    Re: Copying file to destination: how to preserve directory hierarchy?

    Quote Originally Posted by MacUntu View Post
    I have a text file containing a list of files like:

    Code:
    /etc/modprobe.d/blacklist.conf
    /etc/rsyslog.d/50-default.conf
    /etc/ufw/ufw.conf
    /lib/bootchart/gather
    /lib/resolvconf/list-records
    /usr/lib/php5/20060613+lfs/gd.so
    /usr/lib/php5/20060613+lfs/pdo.so
    How would I copy them to a target directory while keeping the directory hierarchy intact?

    I can't do
    Code:
    for file in list: cp file target
    because that would put all files in the target directory.

    I also cannot do
    Code:
    for file in list: cp file target/file
    because direcotries like /etc or /usr/lib/php5 don't exist.

    Any help is appreciated, TIA!
    Perhaps the program 'cpio' can help.

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Copying file to destination: how to preserve directory hierarchy?

    Code:
    cp --parents source target

  4. #4
    Join Date
    Sep 2006
    Location
    Central Europe
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Copying file to destination: how to preserve directory hierarchy?

    Quote Originally Posted by Arndt View Post
    Perhaps the program 'cpio' can help.
    Thanks, why don't I know about that program? Unfortunately it creates all directories with the user running cpio (while preserving ownership of the files).

    Quote Originally Posted by sisco311 View Post
    Code:
    cp --parents source target
    That's it! Thanks, seems I misinterpreted '--parents'.
    The Power User’s Guide to Unity
    Questions about Ubuntu? Ask them at askubuntu.com!

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
  •