[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9153.0. "tar with wildcard" by HTSC12::MICKWIDLAM (Water addict, water man) Thu Mar 13 1997 03:24

I have a very silly question but I can't found answer. What wildcard can tar
command use?

Thanks,
Mickwid.
T.RTitleUserPersonal
Name
DateLines
9153.1NoneRHETT::PARKERThu Mar 13 1997 09:006
    
    None - the shell(s) expands all wildcards. What exactly are you trying
    to do? May be able to offer more help if you tell us that...
    
    Lee
    
9153.2abc.*, abc*.defHTSC12::MICKWIDLAMWater addict, water manThu Mar 13 1997 10:197
    re .1
    
    I would like to extract some files like abc.* or abc*.def. Is there any
    generic way?
    
    Regards,
    Mickwid.
9153.3VAXCPU::michaudJeff Michaud - ObjectBrokerThu Mar 13 1997 10:4416
> I would like to extract some files like abc.* or abc*.def. Is there any
> generic way?

	You'll have to do a "tar t" to get the list of files in the tar
	file/tape and you can then use grep/egrep with regular expressions
	for what you want. Ex.

		% tar t >list
		% tar x `egrep 'abc\..*|abc.*\.def$' list`

	if the list of files you want to extract is too long that it
	exceeds the max argv size:

		% tar t >list
		% egrep 'abc\..*|abc.*\.def$' list >extlist
		% tar xR extlist
9153.4I can't seem to make it workRHETT::PARKERThu Mar 13 1997 11:046
    
    Tha man page sort of implies you can do this, but I can't get it to
    work. Maybe someone else can tell us if there is a way...
    
    Lee
    
9153.5Use pax.QUARRY::reevesJon Reeves, UNIX compiler groupThu Mar 13 1997 16:051
See man page for details.
9153.6find and tar with R optionSEAWLF::COLEDigital NSIS, Greenbelt, MarylandMon Mar 17 1997 09:4311

	Or use the find command to generate a list of files
	and use the R option on tar to read this list:

		find . -name "*.doc" -print > mylist
		tar -c -R mylist -f outputfile


	...larry

9153.7VAXCPU::michaudJeff Michaud - ObjectBrokerMon Mar 17 1997 11:158
> 	Or use the find command to generate a list of files
> 	and use the R option on tar to read this list:
> 
> 		find . -name "*.doc" -print > mylist
> 		tar -c -R mylist -f outputfile

	reread .0 :-)  the author wants to "extract", not "create"
	a tar archive using wildcards...
9153.8silly me !PRMS00::COLETue Mar 18 1997 09:212
    Silly me !
    
9153.9does work, escape wildcards!TUXEDO::CHUBBWed Mar 19 1997 15:3045
    This will work fine.  You just must escape the wildcards on the
    extraction.  Also be aware that if you create the tar file using . (or
    some other directory) the filenames within won't be simple.
    
    Example:
    % cat | tee 1file 2file 3file > foo      # just to make several files
    Just testing.  
    % ls
    1file   2file   3file   foo
    % cat ?file
    Just testing.
    Just testing.
    Just testing.
    % wc -l !$ 
             1 1file
             1 2file
             1 3file
             3 total
    % cat foo
    Just testing.
    % tar cvf ../test.tar *
    a 1file 1 Blocks
    a 2file 1 Blocks
    a 3file 1 Blocks
    a foo 1 Blocks
    % ls
    1file   2file   3file   foo
    % rm *
    % tar tvf ../test.tar
    blocksize: 20
    -rw-rw-r--  1288/0       14 Mar 19 15:23:02 1997 1file
    -rw-rw-r--  1288/0       14 Mar 19 15:23:02 1997 2file
    -rw-rw-r--  1288/0       14 Mar 19 15:23:02 1997 3file
    -rw-rw-r--  1288/0       14 Mar 19 15:23:02 1997 foo
    % tar xvf ../test.tar \?file
    blocksize: 20
    x 1file, 14 bytes, 1 tape blocks
    x 2file, 14 bytes, 1 tape blocks
    x 3file, 14 bytes, 1 tape blocks
    % 
    
    Notice that 'foo' wasn't extracted.
    
    -- brandon