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.
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.
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.
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.
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 / 一時ディレクトリ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.