• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

tar directory but not its content

I have built a file list which contains a list of directories and files to be tar-ed. However, for a certain directory, not all its subdirectories and files should be tar-ed. Only those in the list should be. I tried with command option "-I" or pipe "| xargs" like followings:

tar cvf <tar_file> -I <list_file>
cat <list_file> | xargs cvf <tar_file>

However, tar command automatically include all the directory contents which has some files should be excluded. Is there an tar command option not extend to its contents?

 
0
gs_kanata
Asked:
gs_kanata
  • 2
  • 2
  • 2
  • +2
2 Solutions
 
a1jCommented:
--exclude=PATTERN
0
 
gs_kanataAuthor Commented:
There is no such pattern for those files and can be anything.
0
 
a1jCommented:
so use --exclude='dirname/*'   that will store dirname but not the files in it. You can specify several --esclude switches for all empty directories or directory pattern sych as --exclude='/*name*/*'  make sure to put pattern in single quotes so shell will not expand it inline.
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
theKashyapCommented:
How abt --no-recursion
Or
cd <dir to tar>; tar -cvf my.tar `find . -type f -depth 1`

Open in new window

0
 
theKashyapCommented:
I checked this works:

tar --no-recursion -cvf my.tar /dir_to_tar/*

Open in new window

0
 
simon3270Commented:
An alternative would be to use cpio.

The lines in the list of files+directories (called file.lst below) should be of the form
  ^file1$
  ^dir1/file2$
  ^dir2/file4$
   ^dir3$
and so on

    find * | grep -f file.lst | cpio -oc > output.cpio

The above will add file1, file2 and file4 to the cpio archive, and a directory entry for dir3 (but no files within dir3).

if you must have bare names (without the ^ and $) in file.lst, a simple sed command can add them for the grep command.
0
 
woolmilkporcCommented:
Seems it's Solaris, and Solaris' tar has neither --no-recurse nor --exclude.

I'd recommend installing GNU tar, to be able to use the suggested options.

With Solaris' tar you're most probably lost, because -I filename acts as if the content of filename had been entered on the command line, which implies recursion.

wmp
0
 
gs_kanataAuthor Commented:
Just alternate way.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now