Check if the file is in the archive

We all use gzip-ped tar achrives (.tar.gz) like mad. Sometimes, though, we need to check if the file is in the archive without extracting the whole damn thing on to the poor hard disk :)

Consider for example, the presence of the .spec file in the .tar.gz, so that you can build an RPM:

[leonid@home tmp]$ tar tzvf somefile.tar.gz | grep somefile.spec

Another need arises sometimes – to check if the archive will extract into a newly created directory or if it will mess up with the content of the current directory (some people still do it). Here is how the proper archive will look:

[leonid@home tmp]$ tar tzvf somefile.tar.gz





In the above example you can see, that you will extract the archive (tar xzvf somefile.tar.gz), then it will create a directory somefile and place all it’s content there. Below is the example of the bad archive which will mess up your current directory.

[leonid@home tmp]$ tar tzvf somefile.tar.gz





To extract this archive and be able to clean it up lately do the following:

[leonid@home tmp]$ mkdir somefile

[leonid@home tmp]$ mv somefile.tar.gz somefile/

[leonid@home tmp]$ cd somefile

[leonid@home somefile]$ tar xzvf somefile.tar.gz

That’s it.

Leave a Comment