You can copy the contents of a folder /source to another existing folder /dest with the command:

cp -a /source/. /dest/

The -a option is an improved recursive option, that preserves all file attributes and symlinks.

The . at end of the source path is a specific cp syntax that copies all files and folders, including hidden ones.

Answer from enzotib on askubuntu.com
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ the-linux-cp-command-how-to-copy-files-in-linux
The Linux cp Command โ€“ How to Copy Files in Linux
June 6, 2022 - If you want to copy more than a file from DirectoryA_1 to DirectoryA_2, you will use the cp command like this: cp ./DirectoryA_1/README.txt ./DirectoryA_1/ANOTHER_FILE.txt ./DirectoryA_2
Discussions

bash - Copy files from one directory into an existing directory - Stack Overflow
In bash I need to do this: take all files in a directory copy them into an existing directory How do I do this? I tried cp -r t1 t2 (both t1 and t2 are existing directories, t1 has files in it) bu... More on stackoverflow.com
๐ŸŒ stackoverflow.com
cp - How do I create a copy of a directory in Unix/Linux? - Stack Overflow
I want to recursively create a copy of a directory and all its contents (e.g. files and subdirectories). More on stackoverflow.com
๐ŸŒ stackoverflow.com
Linux cp command to copy a folder to current directory - Stack Overflow
I am wondering if there is an identical command for copying a folder to current directory like it did using the old MS-DOS. Let's say my current directory location is: /var/www/ I have folders and... More on stackoverflow.com
๐ŸŒ stackoverflow.com
cp - Copy only regular files from one directory to another - Unix & Linux Stack Exchange
I'd like to copy a content of directory 1 to directory 2. However, I'd like to only copy files (and not directories) from my directory 1. How can I do that? cp dir1/* dir2/* then I still have the More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
November 20, 2013
๐ŸŒ
E-Learning@VIB
elearning.vib.be โ€บ courses โ€บ linux โ€บ lessons โ€บ concepts-and-basic-commands-in-linux โ€บ topic โ€บ moving-and-coping-content
Moving and Copying content in Linux โ€“ E-Learning@VIB
August 31, 2023 - List the contents of the backup folder and you should have the file copied. ... In other cases if you want to just move, you need to mv (move) an item like this: mv file_example.txt ~/Documents/new_Directory/ This will move the file inside of the folder new_Directory. However, the command mv (move) is also used to rename items, so if you type mv file_example.txt new_file_name.txt, what you are actually doing is renaming your file or directory (moving from one name to the other).
๐ŸŒ
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 - To copy one file to another directory on a local machine, type the source file's full path, followed by the destination directory: rsync -av ~/Documents/my_file.txt ~/destination/backups/ Replace the source path and /destination/backups/ destination ...
๐ŸŒ
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 - If you want to copy the contents ... of directory-1 and the directory itself was copied into the destination. By default, the cp command will overwrite existing files:...
๐ŸŒ
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.
๐ŸŒ
Its Linux FOSS
itslinuxfoss.com โ€บ home โ€บ how to copy files from one directory to another in linux
How to copy files from one directory to another in Linux โ€“ Its Linux FOSS
September 2, 2022 - A file can be copied to a different directory in Linux using either the โ€œcpโ€ command or the โ€œrsyncโ€ tool. Using these commands, single and multiple, as well as all the files inside a directory, can be copied from one directory to another.
Find elsewhere
๐ŸŒ
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 ...
๐ŸŒ
Red Hat
redhat.com โ€บ en โ€บ blog โ€บ move-copy-files-linux
Linux fundamentals: How to copy, move, and rename files and directories
November 20, 2025 - This command has many options, but the basic syntax is simple. Run cp {source} {destination} to copy from one place (source) to another (destination). Consider the following example: $ ls -1 dir3 dir4 $ cp dir4/subdir1/file4 .
๐ŸŒ
Stanford
web.stanford.edu โ€บ class โ€บ archive โ€บ cs โ€บ cs107 โ€บ cs107.1186 โ€บ unixref โ€บ topics โ€บ cp
cp and mv (copy and move files and directories)
This will copy the entire assign0 directory into the directory called assign1. If assign1 does not exist, the cp command will create it. The mv command moves files in a similar way to cp. It also doubles as a way to rename a file:
๐ŸŒ
Linuxize
linuxize.com โ€บ home โ€บ linux commands โ€บ how to copy files and directories in linux
How to Copy Files and Directories in Linux | Linuxize
1 month ago - To get a confirmation prompt before overwriting the files, use the -i option: ... By default, when using the cp command to copy a file, the new file will be owned by the user performing the command.
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).

Top answer
1 of 4
30
cp dir1/* dir2

cp will not copy directories unless explicitly told to do so (with --recursive for example, see man cp).

Note 1: cp will most likely exit with a non-zero status, but the files will have been copied anyway. This may be an issue when chaining commands based on exit codes:&&, ||, if cp -r dir1/* dir2; then ..., etc. (Thanks to contrebis for their comment on that issue)

Note 2: cp expects the last parameter to be a single file name or directory. There really should be no wildcard * after the name of the target directory. dir2\* will be expanded by the shell just like dir1\*. Unexpected things will happen:

  • If dir2 is empty and depending on your shell and settings:
    • you may just get an error message, which is the best case scenario.
    • dir2/* will be taken literally (looking for a file/directory named *), which will probably lead to an error, too, unless * actually exists.
    • dir2/* it will just be removed from the command entirely, leaving cp dir1/*. Which, depending on the expansion of dir1/*, may even destroy data:
      • If dir1/* matches only one file or directory, you will get an error from cp.
      • If dir1/* matches exactly two files, one will be overwritten by the other (Bad).
      • If dir/* matches multiple files and the last match is a, you will get an error message.
      • If the last match of dir/* is a directory all other matches will be moved into it.
  • If dir2 is not empty, it again depends:
    • If the last match of dir2/* is a directory, dir1/* and the other matches of dir2/* will be moved into.
    • If the last match of dir2/* is a file, you probably will get an error message, unless dir1/* matches only one file.
2 of 4
16

It's the shell that expands wildcards, not the commands. So cp dir1/* dir2/* first expands the two wildcards, then calls cp on the result. This is not at all what you apparently expect: depending on how many files there are already in dir2, dir2/* may expand to one or more argument. The command cp doesn't know which of its arguments came from expanding the first pattern and which ones came from expanding the second pattern. It expects its last argument to be the name of the destination directory. Thus, to copy all the files from the directory dir1 into the directory dir2, the last argument must be the directory dir2:

cp dir1/* dir2

Since * matches all files, cp attempts to copy all files. This includes directories: directories are files too. It skips directories, but reports an error. It copies the content of special files such as named pipes (something had better be writing to them, or cp will block), etc.

To copy only regular files, you need to restrict the matching. In zsh, you can use the glob qualifier . for that:

cp dir1/*(.) dir2

Other shells don't have this. You can use the find command to filter on file types. Assuming that you're running non-embedded Linux or Cygwin:

find dir1 -maxdepth 1 -type f -exec cp -t dir2 {} +

On Linux, FreeBSD and OSX:

find dir1 -maxdepth 1 -type f | xargs -I {} cp {} dir2
๐ŸŒ
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 - The cp command is used to copy one or more files on a Linux system to a new location. It is similar to the mv command, except it does not move or remove the original file, which remains in place.
๐ŸŒ
Reddit
reddit.com โ€บ r/linuxquestions โ€บ copy a file from one directory to another.
r/linuxquestions on Reddit: copy a file from one directory to another.
September 20, 2021 -

please let me know about the command that I should use to copy a file from a sub-directory which is under a parent directory under home directory to the current directory under the same parent directory ?

๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ how to copy files and directories in linux
How to Copy Files and Directories in Linux: A Beginner's Guide
September 9, 2025 - Learn how to use the cp command in Linux to copy files and directories, with options for preserving attributes and handling overwrites.
Price ย  $
Call ย  +1 844 286 2130
Address ย  1999 Harrison St 1800 9079, 94612, Oakland
๐ŸŒ
FOSS Linux
fosslinux.com โ€บ home โ€บ learn linux โ€บ copying all files and folders to another directory in linux
Copying All Files and Folders to Another Directory in Linux
April 4, 2023 - In this guide, weโ€™ll focus on copying all files from one directory to another using the cp command. The cp command is a simple yet powerful tool that allows you to copy files and directories in Linux.