Windows XCopy function on Linux

Posted on 2011-04-25
Last Modified: 2012-05-11

I have a directory named "dir1"; "dir1" has subdirectories and files.

I need a command that copies "dir1" to another location, with all the files and subdirectories structure (if a subdirectory doesn't exist on the target, it must create it), but i need that such command displays what it is doing.

Is this possible to do?
Question by:kalvillo
    LVL 38

    Expert Comment

    cp -pvr dir1 dir2
    LVL 38

    Accepted Solution

    cp -r (recursively)
    cp -v (verbose, show every file/directory has ben copied over)
    cp -p (preserve the file/dir permission)

    As combine,
    /bin/cp -pvr  /path-to-dir1   /path-to-dir2   # if dir2 doesn't exist, then it is created as well as the sub-dir

    Author Comment

    I have a problem... I already copied all the files using the procedure explained above, but, the files are inaccessible, because only root has access to them.

    Is it possible to copy, preserving the permissions from the source?
    LVL 38

    Expert Comment

    You mean ownership, since your do "cp" as root?
    -p have preserve the permission to make the target have the same permission as the source.

    But the ownership will become whoever you run "cp".

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now