JustBash.Commands.Cp (JustBash v0.4.0)

View Source

The cp command - copy files and directory trees.

Flags:

  • -r/-R/--recursive, and -a/--archive (which implies --recursive) — copy directory trees.
  • -n/--no-clobber — leave an existing destination alone. Bash decides this per file inside a tree; here it is decided per operand.
  • -P/--no-dereference (and -d) / -L/--dereference — copy a command-line symlink as a link, or follow it. As in bash, a shallow copy follows the link and a recursive copy preserves it; -L and -P override that. Links inside a copied tree are always preserved.
  • -v/--verbose — print 'src' -> 'dest' for every copied entry.
  • -f/--force, -p/--preserve and -i/--interactive — accepted, with nothing to do: a copy always overwrites, always carries the source's mode and mtime across, and a sandbox has no terminal to prompt on (so -i proceeds as if the prompt were answered yes).

As in bash, a destination that is an existing directory receives the source under its own basename, and any number of sources may be copied into a trailing directory operand.

A recursive copy refuses a destination inside the source, including one that only reaches it through a symlink (FS.cp/4 resolves both operands first). One wording diverges there: for a destination that does not exist yet, such as cp -r a l/x with l -> a, bash reaches the case through its inode-based self-detection mid-walk and reports will not create hard link, while the path check here gets there first and reports cannot copy a directory, 'a', into itself. Same exit code, same untouched source.