Find the answer to your Linux question:
Results 1 to 3 of 3
so I often need to copy over entire files and sym links from one location (site root) on my server to another. I normally use: Code: cp -r -p /home/cpm186/public_html ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2003
    Posts
    57

    copy over, but leave ownership the same - HOW?


    so I often need to copy over entire files and sym links from one location (site root) on my server to another. I normally use:

    Code:
    cp -r -p /home/cpm186/public_html /home/cpm923/subdomains/example
    I am doing this as root

    then I still need to go in and do this:

    Code:
    cd /home/cpm923/subdomains;
    chown -R cpm923 *; 
    chgrp -R cpm923 *
    Any way I can copy files into another area and have the files automatically inherit owner and group attributes of the folder being dumped into? THANKS! and btw if youneed PHP help, www dot phpbuilder etc is the forum I help out on as that's my strength

    Sam

  2. #2
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    174
    Using "cpio" will do what you want. I've used command strings similar to this one (taken from your example) more times than I can count.

    Code:
    cd /home/cpm186/public_html
    find . -depth -print | cpio -pvmd /home/cpm923/subdomains/example
    You might need to tweak where you "cd" and do something like "find public_html ..." to get the right directory structure created on the destination end. But it will create file preserving ownership and permissions. In fact I used to do something very similar to duplicate entire filesystems to clone boot drives so it handles any type of weird file you might need it to reproduce.

  3. #3
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by cnamejj View Post
    Using "cpio" will do what you want. I've used command strings similar to this one (taken from your example) more times than I can count.

    Code:
    cd /home/cpm186/public_html
    find . -depth -print | cpio -pvmd /home/cpm923/subdomains/example
    doesn't that preserve the original permissions, not assign the new ownership requested?

    maybe i misunderstand.

    you could do this w/an rsync command to the local system, as the new user, e.g.:

    Code:
    rsync -av /home/cpm186/public_html cpm923@localhost:/home/cpm923/subdomains/example
    you'll be prompted for a password, if you don't have SSH key pairs up and running. you ought to set up the keys, if you do this regularly. especially if you want to scrip it (run non-interactively).

    Edit: Oh, I see what the OP meant now! I thought he wanted to run it as some other non-root user. if running as root, yeah cpio is good. you could also use rsync with the --owner and --group options....
    Last edited by atreyu; 10-28-2012 at 12:07 AM. Reason: my bad

Posting Permissions

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