Operating System - HP-UX
1831343 Members
3317 Online
110024 Solutions
New Discussion

Re: Checking contents of TAR file

 
SOLVED
Go to solution
Pando
Regular Advisor

Checking contents of TAR file

Dear Gurus,

I have a tar files when checked using -t option have no files in it. Is there a test to check if the tar file contains files or no files at all?

Maximum points to all correct replies.
9 REPLIES 9
Arunvijai_4
Honored Contributor

Re: Checking contents of TAR file

Can you post # tar -tvf ?
also, # ll

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Morcos
Super Advisor

Re: Checking contents of TAR file

tar -tvf /dev/rmt/0m get the table of contents of the archive.

ziad
RAC_1
Honored Contributor

Re: Checking contents of TAR file

Is it a tar files?

file "your_file"

tar -tvf "your_tar_file"
There is no substitute to HARDWORK
GGA
Trusted Contributor

Re: Checking contents of TAR file

hello

with tar -tvf filename u can see if there any files there
if no output comes then is nothing in the file

regards gga
Pando
Regular Advisor

Re: Checking contents of TAR file

Here it is:

# ll PPS1XX15_20051013-144204.tar
-rw------- 1 root sys 10240 Oct 13 14:42 PPS1XX15_20051013-144204.tar

# tar -tvf PPS1XX15_20051013-144204.tar
#
Pando
Regular Advisor

Re: Checking contents of TAR file

Hello All,

What i am looking for is to test the tar file if it contains files. Actually am creating a script for checking if the existing tar files contains file in it, if it contains no file at all, it will be discarded or remove from my system.
Muthukumar_5
Honored Contributor
Solution

Re: Checking contents of TAR file

You can try as,

tar -tvf PPS1XX15_20051013-144204.tar > /tmp/tartest.log

if [ ! -s /tmp/tartest.log ]
then
rm -f PPS1XX15_20051013-144204.tar /tmp/tartest.log
fi

hth.
Easy to suggest when don't know about the problem!
H.Merijn Brand (procura
Honored Contributor

Re: Checking contents of TAR file

# perl -MArchive::Tar -e'for(@ARGV){Archive::Tar->list_archive($_)or unlink$_}' *.tar

Throws away empty tar files

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
VEL_1
Valued Contributor

Re: Checking contents of TAR file

Hi,

You can use the strings command also.

#!/sbin/sh
if [ `strings test.tar| grep ustar| wc -l` -le 1 -a `tar -tvf test.tar| egrep ".*/$"| wc -l` -eq `strings test.tar| grep ustar| wc -l` ]
then
echo "The tar file test.tar contains no files"
else
echo "The tar file test.tar contains some files"
fi


Thanks.