Paths below src contain no newline characters.
Use the find output to create backup.cpio in newc format.
Which command list is correct?
cpio copy-out mode -o reads filenames from standard input and writes the archive to standard output. -H newc selects the archive format.
Detailed explanation
find src -print | cpio -i -H newc > backup.cpioIncorrect. -i is copy-in mode for extracting an archive.
Incorrect. -i is copy-in mode for extracting an archive.
find src -print | cpio -o -H newc > backup.cpioCorrect. find supplies paths, and cpio -o -H newc writes the archive.
Correct. find supplies paths, and cpio -o -H newc writes the archive.
find src -print | cpio -t -H newc > backup.cpioIncorrect. -t lists archive contents rather than creating the archive.
Incorrect. -t lists archive contents rather than creating the archive.
cpio -o -H newc src > backup.cpioIncorrect. This does not read the complete path list from find's standard input.
Incorrect. This does not read the complete path list from find's standard input.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
mkdir "$LAB_DIR/src"
printf demo > "$LAB_DIR/src/file"
(cd "$LAB_DIR" && find src -print | cpio -o -H newc > backup.cpio)
(cd "$LAB_DIR" && cpio -it < backup.cpio)
rm -r "$LAB_DIR"Expected result
src
src/file
※cpioのブロック数メッセージが標準エラーへ出る場合があるKey points
- -o creates an archive
- The path list comes from standard input
- The archive is written to standard output
Notes
- Environment: GNU cpio 2.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.