9951 explained code solutions for 126 technologies


cli-tarHow do I list the files contained in a Unix tar archive?


To list the files contained in a Unix tar archive, the tar command can be used. This command has the -tvf flags, which stands for "list verbosely, the contents of an archive file". An example of this command is shown below:

tar -tvf archive.tar

This command will produce an output similar to this:

-rw-r--r-- user/group    0 2020-07-20 11:55 file1.txt
-rw-r--r-- user/group    0 2020-07-20 11:55 file2.txt
-rw-r--r-- user/group    0 2020-07-20 11:55 file3.txt

The output of this command will list each file contained in the tar archive, including the file's size, date, and permissions.

The command used is composed of the following parts:

  • tar: the command to list the contents of a tar archive
  • -tvf: the flags to list the contents of an archive file verbosely
  • archive.tar: the name of the tar archive

For more information, please refer to the following links:

Edit this code on GitHub