cp command

cp command

https://www.geeksforgeeks.org/cp-command-linux-examples/

cp -R "/Volumes/SIGNATURE/folder1" "/Users/explorer436/Google Drive"

cp -R "/Volumes/SIGNATURE/folder2" "/Users/explorer436/Google Drive"

cp -R "/Volumes/SIGNATURE/folder3/folder4/folder5" "/Volumes/SIGNATURE"

In macOS, while you are using cp command to copy huge folders, to find out how much data is copied, go to Applications -> Utilities -> Activity Monitor -> Disk view. And look at the process name cp

Recursive copy

To copy a directory, including all its files and subdirectories, to another directory, enter (copy directories recursively):

$ cp -R * /home/explorer436/Downloads/destinationFolder

We might have to create destinationFolder before running this command

cp Src_file1 Src_file2 Src_file3 Dest_directory

Do not copy or overwrite existing files or folders

Modern versions of the `cp` command often have an option to prevent overwriting.

cp -rn source_dir/* dest_dir/

or, to also preserve attributes (like permissions, timestamps):

GNU cp (most Linux systems)

cp -arn source_dir/* dest_dir/

Standard POSIX cp (might work on macOS, other Unixes)

cp -prn source_dir/* dest_dir/
  1. -r: Recursive, needed to copy directories and their contents.
  2. -n (--no-clobber): This is the key option. It tells cp not to overwrite any existing file in the destination.
  3. -a (archive, GNU only): Preserves as much structure and attributes as possible (includes -dR --preserve=all, where -d is like --no-dereference --preserve=links and -R is recursive). It’s often simpler than specifying individual preservation flags.
  4. -p (preserve): Preserves mode, ownership, and timestamps (standard POSIX).
  5. source_dir/*: Selects all files and directories inside source_dir. Be aware that this might not handle hidden files (starting with .) correctly depending on your shell settings, and can cause “Argument list too long” errors if you have a huge number of files. rsync doesn’t have these specific limitations.
  6. dest_dir/: The destination directory.

Links to this note