Difference between revisions of "Cp"

From wikieduonline
Jump to navigation Jump to search
Line 33: Line 33:
 
* <code>[[rsync]]</code>
 
* <code>[[rsync]]</code>
 
* <code>[[mv]]</code>
 
* <code>[[mv]]</code>
* <code>[[progress]] -m</code>
+
* <code>[[progress -m]]</code>
 
* <code>[[copy]]</code> ([[Windows]])
 
* <code>[[copy]]</code> ([[Windows]])
 
* <code>[[nfs-cp]]</code>
 
* <code>[[nfs-cp]]</code>

Revision as of 12:00, 30 June 2022

cp[1] command is used for copying files and directories. It lacks progress bar indicator[2], but you can use progress -w or progress -m command to display the percentage of copied data or use rsync[3] command.

Ansible also includes a cp module with limited scalability (>hundreds of files) [4]

Options

-a, --archive
-l, --link hard link files instead of copying
-p same as --preserve=mode,ownership,timestamps
-R, -r, --recursive
--reflink[=WHEN] control clone/CoW copies. --reflink=always
-v verbose, showing files as they are copied.
cp --help
cp: illegal option -- -
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-aclpsvXx] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-aclpsvXx] source_file ... target_directory

Examples

cp -a /source/. /dest/
cp -rp /home/origin /home/destination
cp -rp /home/origin/* /home/destination/
cp file.txt file-`date --iso`.txt

cp /etc/httpd/httpd.{,.BAK}

Activities

  1. Understand the differences between cp, scp and rsync: https://stackoverflow.com/questions/20244585/how-does-scp-differ-from-rsync
  2. Understand --sparse option and usage cases
  3. Learn how to not overwrite a file with -n, --no-clobber option[5] or using rsync -a -v --ignore-existing src dst

Related commands

See also

Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

Source: https://en.wikiversity.org/wiki/Linux/Basic_commands/cp

Advertising: