how to list content in a tar

Subject:

tar tf scripts.tar | awk -F/ '{if (NF<3) print }'scripts/scripts/my2cnf.plscripts/pastebin.shscripts/critic.plscripts/wiki_sys.plscripts/blacklist_update.plscripts/sysinfo.pl

2018-09-04 19:00:40gstlouis

 

Make sure to note, that the number is 3+ however many levels you want, because of the / in the username/group. If you just do

tar tf scripts.tar | awk -F/ '{if (NF<3) print }'
scripts/ scripts/my2cnf.pl
scripts/pastebin.sh
scripts/critic.pl
scripts/wiki_sys.pl
scripts/blacklist_update.pl scripts/sysinfo.pl

gstlouis
vote
2018-09-04 19:02:16

ref: https://stackoverflow.com/questions/2700306/listing-the-content-of-a-tar-file-or-a-directory-only-down-to-some-level

gstlouis
vote
2018-09-04 19:02:28

tar -tvf

gstlouis
vote
2018-09-08 16:34:53

tar stores relative paths by default. GNU tar even says so if you try to store an absolute path:

tar -cf foo.tar /home/foo tar: Removing leading `/' from member names

If you need to extract a particular folder, have a look at what's in the tar file:

tar -tvf foo.tar

And note the exact filename. In the case of my foo.tar file, I could extract /home/foo/bar by saying:

tar -xvf foo.tar home/foo/bar # Note: no leading slash

So no, the way you posted isn't (necessarily) the correct way to do it. You have to leave out the leading slash. If you want to simulate absolute paths, do cd / first and make sure you're the superuser. Also, this does the same:

tar -C / -xvf foo.tar home/foo/bar # -C is the ‘change directory’ option

There are very obvious, good reasons why tar converts paths to relative ones. One is the ability to restore an archive in places other than its original source. The other is security. You could extract an archive, expect its files to appear in your current working directory, and instead overwrite system files (or your own work) elsewhere by mistake.

gstlouis
vote
2018-09-08 16:50:40