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.
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.
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.
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.
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.
The option you're looking for is -R
.
cp -R path_to_source path_to_destination/
destination
doesn't exist, it will be created.-R
means copy 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):cp -a path_to_source/. path_to_destination/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With