Copy Directory/Folder in Linux
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Copy a Directory in Linux:
To copy files or directories in Unix-based operating systems (Linux and MacOS), you use the
cp
command.If you have a file named
a.txt
, and you want a copy of that file namedb.txt
:How to copy a file to another directory:
To copy a file to a directory that is different from your current directory, you just need to pass the path of the other directory as the destination:
How to copy multiple files to a directory:
To copy more than one file at a time you can pass multiple input sources and a directory as destination:
How to copy a directory to another directory:
To copy a directory, you need to add the
-r
(or-R
) flag—which is shorthand for--recursive
:Copying directories on Linux is a big part of every system administrator routine.
In some cases, you may need to copy some directories on your system in order revamp your main filesystem structure.
In this tutorial, we are going to see how you can easily copy directories and folders on Linux using the cp command.
Copy Directories on Linux:
Copy multiple directories with cp:
How do I copy folder with files to another folder in Unix/Linux:
The option you’re looking for is
-R
.destination
doesn’t exist, it will be created.-R
meanscopy directories recursively
. You can also use-r
since it’s case-insensitive.-a
flag along with trailing/.
in the source (as per@muni764
’s /@Anton Krug
’s comment):