1833568 Members
3470 Online
110061 Solutions
New Discussion

"Tar" Command

 
Karthikeyan_5
Frequent Advisor

"Tar" Command

How to list all the files starting with "a" on the DAT/TAPE using "tar" command
10 REPLIES 10
John Payne_2
Honored Contributor

Re: "Tar" Command

tar -cvf /dev/rmt/0 |grep a* |more

Should list it for you. (Where /dev/rmt/0 is your tape device.)

Hope it helps

John
Spoon!!!!
John Payne_2
Honored Contributor

Re: "Tar" Command

OOPS!

Thats 'tar -tvf /dev/rmt/0 |grep a* |more'

(My brain siezed. The 'c' option of tar is for writing, not reading.)

John
Spoon!!!!
PIYUSH D. PATEL
Honored Contributor

Re: "Tar" Command

Redirect to a file and read that file

tar -tvf /dev/rmt/0m |grep a* > /tmp/test

HTH,
Piyush

Paul Sperry
Honored Contributor

Re: "Tar" Command

tar -tvf /dev/rmt0 |grep a* |more
Robert Gamble
Respected Contributor

Re: "Tar" Command

Or

I suggest you redirect the output to a file if you suspect there are lot of files that start with 'a'

tar -tvf /dev/rmt/0 | grep a* > /tmp/foo.out
Dario_1
Trusted Contributor

Re: "Tar" Command

Hi!!

Try:

tar -tvf /dev/rmt0 |grep a* |pg

or

tar -tvf /dev/rmt0 |grep a* > filename

Regards,

DR
Bill Hassell
Honored Contributor

Re: "Tar" Command

Actually, grep a* is not going to produce the right resultant for 2 reasons:

1. The shell will automatically expand a* to match any filenames in the current working directory which won't produce a meaningful result.

2. a* matches the letter a anywhere in the filename, not just the first character, and the filename is located at the end of the tar -tvf listing.

You'll need to extract the filename portion fromn the tar output using something like awk, then extract the basename of the file itself (in case there are leading directories stored on the tape) and finally, anchor the search to the begining of the filename as in:

tar tvf /dev/rmt/0m | awk '{print $NF}' | while read MYFILE;do echo $(basename $MYFILE) | grep ^a ; done

Test this command with other letters like ^b or ^s to see that it produces the desired result. Note that tar, unlike fbackup and other commercial tools, has no central index dso the entire tape must be read to get an index. You might want to grab the index in one command and sort the result into a file for easy scanning:

tar tvf /dev/rmt/0m | awk '{print $NF}' | sort > /var/tmp/filenames

(sorts using full pathname)

tar tvf /dev/rmt/0m | awk '{print $NF}' | while read MYFILE;do echo $(basename $MYFILE) | sort > /var/tmp/filenames

(sorts by the filename only)


Bill Hassell, sysadmin
vasundhara
Frequent Advisor

Re: "Tar" Command

Hi,

you can list the cut the file name filed from tar tvf command and then pass this input for files starting with 'a'. In general file name is 8th filed of tar tvf output. If it is not 8th filed, replace 8 with filed number.

tar tvf |cut -d' ' -f |grep ^a

Regards
VJ.
Peter Nikitka
Honored Contributor

Re: "Tar" Command

In addition to Bills comment,
I suggest the following command line (assuming you look for files with 'a'):
tar tf | awk -F/ -v ff=a '$NF ~ "^"ff'

To get just the filenames, you do not need the verbose option, and in using separator '/', you have no problems with file/dirnames, containing spaces.
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Jean-Louis Phelix
Honored Contributor

Re: "Tar" Command

Hi

Sometimes using a more clever tool can be useful ... Use pax and be careful to quotes !

pax -vf /dev/rmt/0 "a*"

See man pax for more details (it can read tar and cpio format and is used by ignite-UX)

Regards.
It works for me (© Bill McNAMARA ...)