Which tar command option is used to list the files in a tape archive format?
a) cvf
b) tvf
c) xvf
d) ovf
The Correct Answer and Explanation is:
Correct answer: b) tvf
The tar command in Unix/Linux is used to create, extract, and list files in a tape archive (tar) format. Among its many options, tvf is specifically used to list the contents of a tar archive without extracting them.
Explanation:
The tar command uses a combination of options, where:
tstands for “list” (table of contents),vstands for “verbose” (shows detailed file information),fstands for “file” (specifies the archive file name).
So, the tar tvf archive.tar command reads the file archive.tar and lists all its contents, showing details like file names, sizes, modification times, and permissions.
Breakdown of Options:
cvf– This is used to create a new tar archive.c: create a new archivev: verbosef: file (specify the archive name)- Example:
tar cvf archive.tar file1 file2
tvf– This is used to list the contents of a tar archive.t: list filesv: verbosef: file- Example:
tar tvf archive.tar→ lists files insidearchive.tarwith details.
xvf– This is used to extract files from a tar archive.x: extractv: verbosef: file- Example:
tar xvf archive.tar→ extracts all files fromarchive.tar.
ovf– This is not a valid tar option combination. There is noooption in standard tar usage for this purpose.
Summary:
If you want to view what files are stored in a tar archive without extracting them, use:
tar tvf archive.tar
This is particularly useful when you want to check the contents of a large archive before deciding which files (if any) to extract.
