Copy config-tree recursively to backup/config-tree.
Preserve modes, timestamps, ownership where possible, and symbolic links.
Which GNU cp command is most appropriate?
cp -a is archive mode: it includes recursion and requests preservation of key attributes and link structure.
Detailed explanation
cp config-tree backup/Incorrect. Without -a this does not guarantee recursive copying or attribute preservation.
cp -L config-tree backup/Incorrect. -L follows symbolic links rather than preserving them.
cp -a config-tree backup/Correct. cp -a config-tree backup/ requests the archive copy behavior.
cp -u config-tree backup/Incorrect. -u controls update copying but not complete attribute preservation.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir "$tmp/src"; printf x >"$tmp/src/file"; ln -s file "$tmp/src/link"; cp -a "$tmp/src" "$tmp/dst"; test -L "$tmp/dst/link" && echo symlink-preserved; rm -rf "$tmp"Expected result
symlink-preservedKey points
- -a means archive
- It includes recursion
- Symbolic links are preserved
Notes
- Environment: GNU coreutils 9.x / 一時ディレクトリ
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
Archive-style copying is different from following a link to its target; the requested result keeps the link structure.
Check the side effect
Use a temporary tree containing a link and inspect the destination with a link-aware listing.