Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy folder with files to another folder in Unix/Linux? [closed]

Tags:

linux

cp

I am having some issues to copy a folder with files in that folder into another folder. Command cp -r doesn't copy files in the folder.

like image 209
user2080656 Avatar asked Feb 17 '13 15:02

user2080656


People also ask

How do you copy the entire folder to another place in Unix?

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) and the options you pass to it.

How do you copy all files in a folder to another folder in Linux?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.

How do I copy a folder and subfolders without files in Linux?

Overview. We know we can copy a directory recursively using the cp command and the -R option. In this way, the source directory, together with all the files under it, will be copied to the destination.

How do I copy only the contents of a folder in Linux?

cp is the command to copy using a terminal, -r makes it recursively (so, current directory + further directories inside current) ~/folder1 is the origin folder, ~/new_folder1 is the destination folder for the files/folders inside the origin.


1 Answers

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/ 
like image 148
Pierre Salagnac Avatar answered Oct 09 '22 20:10

Pierre Salagnac