Recursively copy project into backup/project.
Preserve permissions, timestamps, and symbolic links as far as possible.
Which GNU cp command is appropriate?
cp -a enables archive mode, combining recursive copying with preservation of attributes and symbolic links.
Detailed explanation
cp -a project backup/Correct. Archive mode recursively copies the directory and preserves metadata and links.
Correct. Archive mode recursively copies the directory and preserves metadata and links.
cp project backup/Incorrect. Plain cp does not recursively copy a directory.
Incorrect. Plain cp does not recursively copy a directory.
cp -L project backup/Incorrect. -L follows symbolic links instead of preserving the links themselves.
Incorrect. -L follows symbolic links instead of preserving the links themselves.
mv project backup/Incorrect. mv relocates the source rather than making a backup copy.
Incorrect. mv relocates the source rather than making a backup copy.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
mkdir -p "$LAB_DIR/project" "$LAB_DIR/backup"
printf data > "$LAB_DIR/project/file"
ln -s file "$LAB_DIR/project/link"
cp -a "$LAB_DIR/project" "$LAB_DIR/backup/"
test -L "$LAB_DIR/backup/project/link" && echo LINK_PRESERVED
rm -r "$LAB_DIR"Expected result
LINK_PRESERVEDKey points
- -a includes recursive copying
- Preserving metadata where possible
- Treating symbolic links as links
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.