How to Copy Folder with Files to Another Folder in Unix/Linux

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

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/

UNIX How to copy entire directory (subdirectories and files) from one location to another and retain permissions

from man cp

-p    Cause cp to preserve the following attributes of each source file
in the copy: modification time, access time, file flags, file mode,
ACL, user ID, and group ID, as allowed by permissions.

so cp -pr

How to move or copy files listed by 'find' command in unix?

Adding to Eric Jablow's answer, here is a possible solution (it worked for me - linux mint 14 /nadia)

find /path/to/search/ -type f -name "glob-to-find-files" | xargs cp -t /target/path/

You can refer to "How can I use xargs to copy files that have spaces and quotes in their names?" as well.

Linux cp command to copy a folder to current directory

Just omit the -T parameter, as that's what prevents the command from working properly:

cp -r /home/hope/subfolder .

The -T parameter treats the target argument as a file, so no copying will be performed at all if that is actually a directory.

A friendly reminder: virtually all Unix commands have a --help command line argument that is worth trying out in case of a trouble :)

Unix - copy contents of one directory to another

Try this:

cp Folder1/* Folder2/

Copy or move all files in a directory regardles of folder depth or number

You can do it like this:

find /absolute/path/to/Pictures -type f -name '*.png' -exec mv -i {} /absolute/path/to/results  \;

Another option is to use xargs

find /absolute/path/to/Pictures -name '*.png' | xargs -I files mv files /absolute/path/to/results

How to copy a specific file in a folder using terminal

Copy command works well.

cp /currentfolder/filename /currentfolder/newfilename


Related Topics



Leave a reply



Submit