I want to execute a dry run of a tar compression and print the entries to stdout without actually creating the tar.

So far I've tried:

// just spins
$ tar t -O Downloads
$ tar c -O Downloads
tar: Option -O is not permitted in mode -c

tar --help gives the following:

⋊> ~ tar --help                                                                                                                                                                                 08:06:22
tar(bsdtar): manipulate archive files
First option must be a mode specifier:
  -c Create  -r Add/Replace  -t List  -u Update  -x Extract
Common Options:
  -b #  Use # 512-byte records per I/O block
  -f <filename>  Location of archive
  -v    Verbose
  -w    Interactive
Create: tar -c [options] [<file> | <dir> | @<archive> | -C <dir> ]
  <file>, <dir>  add these items to archive
  -z, -j, -J, --lzma  Compress archive with gzip/bzip2/xz/lzma
  --format {ustar|pax|cpio|shar}  Select archive format
  --exclude <pattern>  Skip files that match pattern
  -C <dir>  Change to <dir> before processing remaining files
  @<archive>  Add entries from <archive> to output
List: tar -t [options] [<patterns>]
  <patterns>  If specified, list only entries that match
Extract: tar -x [options] [<patterns>]
  <patterns>  If specified, extract only entries that match
  -k    Keep (don't overwrite) existing files
  -m    Don't restore modification times
  -O    Write entries to stdout, don't restore to disk
  -p    Restore permissions (including ACLs, owner, file flags)
bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6

2 Answers 2


To do a dry-run just listing files, use -v for verbose mode to list the files and use /dev/null as output to avoid the time/space overhead of writing an acutal file. Exclude -v if you just want to see tar errors.

tar -cvf /dev/null mydir 
  • 1
    I like this better - single command with no pipe. I have no idea if it is more efficient.
    – mrtumnus
    Mar 25, 2021 at 22:15

tar t lists an existing archive. You haven't provided any as an argument (-f), so it's waiting for it on stdin. Humans are no good at typing tar archives on a keyboard, so it's not very useful.

tar c doesn't accept an -O option. It's an option to x as indicated in the help message.

You can combine those two to get expected result:

tar c Downloads | tar t

There's no -f argument to tar c, so it will write compressed output to stdout. We're then piping it to tar t's stdin, using the mode in which it was "stuck" previously.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .