brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tar -tf lists an archive without unpacking it

Archive
~/tips/tar-list

tar -tf backup.tar.gz | head

Shows what is inside a tar archive without extracting it, and pulls out a single file.

I do not like unpacking an archive to find out what is inside. It makes a mess in the current folder, and with a big archive it takes a while.

tar -tf backup.tar.gz | head
tar -xf backup.tar.gz path/inside/config.yml -C /tmp

-t only lists the contents. GNU tar and bsdtar both work out the compression on their own when reading, so there is no z or j to remember. The second line takes out one file and puts it in /tmp with -C.

Caveat: the path must match the listing exactly, including any leading folder. With an archive from someone else, read the list first and look for absolute paths or ../ before you extract anything.

Further reading: GNU tar manual

More Archive tips tar --exclude-vcs -czf project.tar.gz project/ All Archive tips (2) All topics

Link