Sample output
drwxr-xr-x ada/staff 0 2026-08-28 14:32 project/
-rw-r--r-- ada/staff 1420 2026-08-28 14:30 project/package.json
-rw-r--r-- ada/staff 285 2026-08-28 14:30 project/tsconfig.json
drwxr-xr-x ada/staff 0 2026-08-28 14:31 project/src/
-rw-r--r-- ada/staff 3874 2026-08-28 14:31 project/src/index.ts
-rw-r--r-- ada/staff 9216 2026-08-28 14:31 project/src/parser.ts
drwxr-xr-x ada/staff 0 2026-08-28 14:32 project/dist/
-rw-r--r-- ada/staff 14208 2026-08-28 14:32 project/dist/index.js
Eight entries, rooted in a project/ directory. The sizes are in bytes, so parser.ts is about 9 KB and dist/index.js is 14 KB. If you expected the archive to contain a flat pile of files with no parent directory, you now know it is safe to extract without scattering files into your current directory.
When you would reach for it
Someone hands you a tarball and you want to know what is in it before you extract files into your working directory. You downloaded a release archive and want to confirm it has a top-level directory wrapping everything, not a loose collection of files. You are debugging a build pipeline that produces a tarball and you need to verify which files made it in and which were left out.
Gotchas
- If the archive was created without a top-level directory, extracting it will scatter files directly into your current directory. Listing first with
-tcatches this. If you spot the problem, extract into a new directory:mkdir tmp && tar -xzvf archive.tar.gz -C tmp. - GNU tar auto-detects compression on extraction (
tar -xfworks regardless of format), but for listing with-tyou still need the correct decompression flag (-z,-j, or-J), or usetar -tfand let GNU tar guess. BSD tar on macOS auto-detects for both-tand-x. - The verbose output format differs slightly between GNU tar and BSD tar. GNU tar shows
user/group, BSD tar showsuser groupwith spaces. The information is the same, the alignment is different.
Variants
$ tar -tzvf archive.tar.gz | grep '\.conf$'
Filter the listing to find specific files. Useful when the archive has hundreds of entries and you only care about config files
$ tar -tzvf archive.tar.gz | wc -l
Count how many files and directories are in the archive without scrolling through the full listing
$ curl -sL https://example.com/release.tar.gz | tar -tzvf -
List the contents of a remote tarball without downloading it to disk first. The -f - tells tar to read from stdin, and curl streams the data through the pipe