cp for filesystem

Copy files using uutils/coreutils cp.

Signature

> cp {flags} ...rest

Flags

  • --recursive, -r: copy directories recursively
  • --verbose, -v: explicitly state what is being done
  • --force, -f: if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used). currently not implemented for windows
  • --interactive, -i: ask before overwriting files
  • --update, -u: copy only when the SOURCE file is newer than the destination file or when the destination file is missing
  • --progress, -p: display a progress bar
  • --no-clobber, -n: do not overwrite an existing file
  • --preserve, - {list<string>}: preserve only the specified attributes (empty list means no attributes preserved) if not specified only mode is preserved possible values: mode, ownership (unix only), timestamps, context, link, links, xattr
  • --debug, -: explain how a file is copied. Implies -v

Parameters

  • ...rest: Copy SRC file/s to DEST.

Input/output types:

inputoutput
nothingnothing

Examples

Copy myfile to dir_b

> cp myfile dir_b

Recursively copy dir_a to dir_b

> cp -r dir_a dir_b

Recursively copy dir_a to dir_b, and print the feedbacks

> cp -r -v dir_a dir_b

Move many files into a directory

> cp *.txt dir_a

Copy only if source file is newer than target file

> cp -u a b

Copy file preserving mode and timestamps attributes

> cp --preserve [ mode timestamps ] a b

Copy file erasing all attributes

> cp --preserve [] a b