The option you're looking for is -R.

cp -R path_to_source path_to_destination/
  • If destination doesn't exist, it will be created.
  • -R means copy directories recursively. You can also use -r since it's case-insensitive.
  • To copy everything inside the source folder (symlinks, hidden files) without copying the source folder itself use -a flag along with trailing /. in the source (as per @muni764's / @Anton Krug's comment):
cp -a path_to_source/. path_to_destination/
Answer from Pierre Salagnac on Stack Overflow
Top answer
1 of 3
2518

The option you're looking for is -R.

cp -R path_to_source path_to_destination/
  • If destination doesn't exist, it will be created.
  • -R means copy directories recursively. You can also use -r since it's case-insensitive.
  • To copy everything inside the source folder (symlinks, hidden files) without copying the source folder itself use -a flag along with trailing /. in the source (as per @muni764's / @Anton Krug's comment):
cp -a path_to_source/. path_to_destination/
2 of 3
393

You are looking for the cp command. You need to change directories so that you are outside of the directory you are trying to copy.

If the directory you're copying is called dir1 and you want to copy it to your /home/Pictures folder:

cp -r dir1/ ~/Pictures/

Linux is case-sensitive and also needs the / after each directory to know that it isn't a file. ~ is a special character in the terminal that automatically evaluates to the current user's home directory. If you need to know what directory you are in, use the command pwd.

When you don't know how to use a Linux command, there is a manual page that you can refer to by typing:

man [insert command here]

at a terminal prompt.

Also, to auto complete long file paths when typing in the terminal, you can hit Tab after you've started typing the path and you will either be presented with choices, or it will insert the remaining part of the path.

There is an important distinction between Linux and Unix in the answer because for Linux (GNU and BusyBox) -R, -r, and --recursive are all equivalent, as mentioned in this answer. For portability, i.e. POSIX compliance, you would want to use -R because of some implementation-dependent differences with -r. It's important to read the man pages to know any idiosyncrasies that may arise (this is a good use case to show why POSIX standards are useful).

Discussions

Copy folder and files inside directory to another directory, which are modified within the last 30 minutes
Seems all you are seeking is rsync. Could be as simple as: rsync -a /home/user/abc/* /home/user/xyz/ More on reddit.com
๐ŸŒ r/linuxquestions
6
3
December 17, 2020
cp - How can I copy a directory and rename it in the same command? - Unix & Linux Stack Exchange
Currently, I'm running these two commands to create a quick backup of the directory. Is there a way to combine the two commands into one, so that I am copying and renaming the new directory in one More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
copying all file
I'm not sure if you're looking for a better way to do this, or just an explanation about why it doesn't work. A simple way to accomplish what you want is to use * instead of .. At the end of your source directory. cp -i /source/* /destination As for why you're seeing the behavior you're seeing... Hopefully someone can help clear this up for me, because I got a bit confused while looking into it. The simple explanation would be that . represents a directory, and cp will not copy any directories without the -r option. That being said, cp doesn't really seem to handle it as a directory. This seems to be because the trailing . character isn't expanded by the shell, and is instead interpreted by cp internally. The way cp handles it is... weird. It seems like kind of a special case. Practically it can be used to specify hidden files in a recursive copy. cp -r /source/. /destination will copy all files in the source directory including hidden files. cp -r /source/* /destination will copy all files in the source directory excluding hidden files. In both cases the directory itself isn't copied, just the contents. In the example above the . does not seem to represent a directory. It behaves more like a special wildcard character that includes hidden files. That would indicate that cp doesn't consider it a directory, and so -r should not be required... I don't really understand WHY it behaves that way and I can't seem to find any good explanation for it anywhere. So good question. I'm stumped. Hopefully someone else can elaborate. More on reddit.com
๐ŸŒ r/linuxquestions
6
8
June 29, 2018
How do I copy an entire directory and include only 1 type of file extension?
You could use find. In my opinion, it does a way better job for recursive operations like that than cp. find ./old_directory -name "*.txt" -exec cp {} ./new_directory \; With cp, you'd need to take each new branch of the folder tree into account when putting the command line together, with find, you just need to give the base folder. More on reddit.com
๐ŸŒ r/linuxquestions
17
29
October 6, 2022
Top answer
1 of 7
184

You can use cp with the -r (copy recursively) flag and specify the new directory name:

cp -r /path/to/directory /path/to/location/new-name

In the above command replace the given paths with the real ones.

For example, to copy stuff from my home directory to an existing directory named backup and name the new directory stuff-backup (if this directory already exists, note that stuff will be copied into it, not overwrite it), you run:

cp -r ~/stuff ~/backup/stuff-backup

~ is a shortcut for your home directory /home/$USER or /home/zanna in my case. You can omit it if the current working directory is your home directory - you can see this from your prompt

zanna@monster:~$
              ^--the ~ here is where I am - home!

You can add the -v (verbose) flag to make cp report each copy being performed:

$ cp -vr stuff backup/stuff-backup
'stuff/thing1' -> 'backup/stuff-backup/thing1'
'stuff/thing2' -> 'backup/stuff-backup/thing2
...
2 of 7
16

The command you need is simply cp which stands for "copy".

You can use it for example with one of these syntaxes:

cp SOURCEFILE TARGETFILE
cp SOURCEFILE TARGETDIRECTORY

The first variant allows you to specify a new file name for the target file, while the second variant creates a copy with the same name in the target directory. You must of course substitute the place holders in capital letters with valid paths first.

However, cp by default operates on files only, not on directories. To get it to copy a complete directory with all its content recursively, you must add the -r option:

cp -r SOURCEDIRECTORY TARGETDIRECTORY

You can learn more about the cp command by typing man cp in your terminal.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ linux-unix โ€บ cp-command-linux-examples
cp Command in Linux - GeeksforGeeks
4 days ago - The cp command has a flexible syntax depending on whether you are copying a single file, multiple files, or directories. cp [options] <source> <destination> cp [options] <source1> <source2> ... <destination_directory> ... When the cp command ...
๐ŸŒ
Built In
builtin.com โ€บ articles โ€บ linux-cp-command
Linux cp Command: How to Copy a File or Directory | Built In
Short for โ€œcopy,โ€ the cp command is used in Linux to duplicate files or entire directories from one location of the file system to another.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-copy-a-directory-in-linux-use-the-cp-command-to-copy-a-folder
How to Copy a Directory in Linux โ€“ Use the cp Command to Copy a Folder
May 3, 2023 - Often times you'll want to copy a folder in Linux to perform specific tasks โ€“ maybe for backup, sharing, editing, an so on. This is a frequent task that you can perform using the cp command. The cp command is a simple yet powerful command ...
Find elsewhere
๐ŸŒ
Linode
linode.com โ€บ docs โ€บ guides โ€บ how-to-copy-files-and-directories-in-linux
How to Copy Files and Directories in Linux | Linode Docs
July 18, 2022 - It is similar to the mv command, except it does not move or remove the original file, which remains in place. Like most Linux commands, cp is run using the command line of a system terminal.
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ sysadmin โ€บ how to copy files and directories in linux
How to Copy Files and Directories in Linux (With Examples)
December 19, 2025 - In addition, rsync creates a new directory if the final part of the destination path specifies a non-existent location. To copy one file to another directory on a local machine, type the source file's full path, followed by the destination directory:
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ linux โ€บ copy folder with files to another folder in linux
Copy folder with files to another folder in Linux | Sentry
In the command, we use source/. instead of source to take advantage of Bash globbing and ensure we copy any hidden files or folders, which would be missed if we just used source. To read more about cp, type man cp into your terminal.
๐ŸŒ
Reddit
reddit.com โ€บ r/linuxquestions โ€บ copy folder and files inside directory to another directory, which are modified within the last 30 minutes
r/linuxquestions on Reddit: Copy folder and files inside directory to another directory, which are modified within the last 30 minutes
December 17, 2020 -

Hi guys,
I have two folders : /home/user/abc & /home/user/xyz

I run a script that generates a folder with files inside abc, so end result would be /home/user/abc/generatedFolder1/ with a bunch of files in it.

Is there a command I could use to copy this generatedFolder1 and the files in it to xyz, so the folder structure would remain the same? I did some googling around but most commands just would either omit the directory or copy the files too, to the xyz directory directly.

Stuff like :

find /home/user/abc/ -type d -mmin -30 -exec cp -pf {} /home/user/xyz/ \;

did not work, idk why. Can someone help me, Im a little new to the find command and am finding it a little confusing. I tried the above command with -r after the cp, and it just creates the abc folder recursively without stopping?

๐ŸŒ
EaseUS
easeus.com โ€บ data recovery resource โ€บ how to copy linux directory and contents
4 Ways to Copy Directory and Contents to Another Location (Linux) - EaseUS
February 12, 2026 - Keep in mind that the /mkv_backup folder is also there at the root of your filesystem. Therefore for copying the /mkv directory to this backup folder, the command you need to use is: ... Step 3.Once done, the /mkv folder will successfully be copied into the /mkv_backup. You have successfully copied one folder into another on Linux.
๐ŸŒ
Warp
warp.dev โ€บ terminus โ€บ linux-copy-directory
Warp: How To Copy A Directory In Linux
July 26, 2024 - Learn how to copy directories and their content in Linux using the cp command with options like -r for recursive copying, -i for interactive mode, and -a for preserving attributes.
๐ŸŒ
nixCraft
cyberciti.biz โ€บ nixcraft โ€บ howto โ€บ commands โ€บ linux โ€“ how to copy a folder [ command line option ]
Linux - How To Copy a Folder [ Command Line Option ] - nixCraft
April 15, 2022 - For example, the following would copy all of the files in a folder named /home/vivek/Documents/ into another existing folder called /data/: cp -v /home/vivek/Documents/* /data/ However, Let us say, you want to copy /var/www/html/ and /home/vivek/projects/ folder and all sub-directories to the /nfs/backup/ directory, then you would type: cp -avr /var/www/html/ /home/vivek/projects/ /nfs/backups/ Prerequisite By default, rsync command may not be installed on your system. Hence, use the apk command on Alpine Linux, dnf command/yum command on RHEL & co, apt command/apt-get command on Debian, Ubuntu & co, zypper command on SUSE/OpenSUSE, pacman command on Arch Linux to install the rsync.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ copy-a-directory-in-linux-how-to-cp-a-folder-in-the-command-line-in-linux-and-unix-macos
Copy a Directory in Linux โ€“ How to cp a Folder in the Command Line in Linux and Unix (MacOS)
May 4, 2021 - By John Mosesman To copy files or directories in Unix-based operating systems (Linux and MacOS), you use the cp command. The cp command is a relatively simple command, but its behavior changes slightly depending on the inputs (files vs directories) ...
๐ŸŒ
Hivelocity
hivelocity.net โ€บ home โ€บ knowledge base articles โ€บ how to move, copy, and rename a directory in linux
How to Move, Copy, and Rename a Directory in Linux
January 5, 2024 - To copy a directory or file in linux, just use the copy command followed by the Source (the directory youโ€™re copying), and the Destination (the place youโ€™re copying it to): cp -R [Source] [Destination]
๐ŸŒ
TOCA
staff.ncl.ac.uk โ€บ jon.dowland โ€บ unix โ€บ website โ€บ unixhelp โ€บ cp.html
Copying files and directories: cp
This copies files sect1c, 2c, 3c and sect4c to the sub-directory partB. To copy a file to another directory from your current directory give name of the source file followed by the pathname to the destination file.
๐ŸŒ
Medium
vibhas1892.medium.com โ€บ copy-files-and-folders-on-linux-dbc6ecafd162
Copy Files and Folders on Linux. cp Command | by Vibha Sharma | Medium
September 23, 2020 - If you want to copy a directory recursively from one location to another using the cp command, use the -r/R option with the cp command. It copies the folder including the subdirectories and their files to the target directory.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ files โ€บ how to copy a directory to an existing directory in linux
How to Copy a Directory to an Existing Directory in Linux | Baeldung on Linux
March 18, 2024 - $ rsync -a --delete src/ target $ tree -a . โ”œโ”€โ”€ src โ”‚ โ”œโ”€โ”€ .hidden.file โ”‚ โ”œโ”€โ”€ srcFile.txt โ”‚ โ””โ”€โ”€ subSrc โ”‚ โ””โ”€โ”€ subSrcFile.txt โ””โ”€โ”€ target โ”œโ”€โ”€ .hidden.file โ”œโ”€โ”€ srcFile.txt โ””โ”€โ”€ subSrc โ””โ”€โ”€ subSrcFile.txt 4 directories, 6 files ยท As the output shows, after we execute the rsync command, target and src contain the same content. So, weโ€™ve solved the problem yet another way. The key to this solution is the option โ€“delete. The โ€“delete option tells rysnc to delete files from target/ that are not in src/. In this way, it ensures that src and target end up identical. In this article, weโ€™ve addressed how to recursively copy a directory to an existing directory with or without overwriting.