?
Solved

ýTAR only one directory levelý

Posted on 2000-04-20
5
Medium Priority
?
287 Views
Last Modified: 2010-04-21
ýMy directory structure is the following:ý

ý/root/1/ý
ý/root/1/aý
ý/root/1/bý
ý/root/1/cý
ý/root/2/ ý
ý/root/2/aý
ý/root/2/bý
ý/root/2/cý
ý…ý
ý/root/999/ ý
ý/root/999/aý
ý/root/999/bý
ý/root/999/cý

ýI would like to tar in one command only the 1st directory levelý
ýAfter root (i.e.  /root/1, /root/2 …/root/999). So that ý
ý/root/1/a  /root/1/b will not be TAR.ý
ýRight now I’m using this command:ý

ýtar -cf - /root | gzip > /home/rami/all_root.tgzý


ýWhich TAR much more then I needý

ýRegards,ý
ýRami Addadyý



0
Comment
Question by:addady
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:tfewster
ID: 2736391
By default, tar recurses down subdirectories; You can exclude files with -X list_of_files_to_exclude, so the following shell script ("arch_dir")will do the job:

#!/bin/sh
#arch_dir:
#Archive directory structure & files at
#top level

# Get full list
find /root > /tmp/rootlist
# Get list of files > 1 level down
grep "/./" /tmp/rootlist > /tmp/exclude
tar -cf - -X /tmp/exclude /root | gzip > /home/rami/all_root.tgz

rm /tmp/rootlist
rm /tmp/exclude

This is inefficient as it has to traverse the full directory tree to generate the list of files to exclude, but once you've created it as a shell script you only have to type one command to run it :)


0
 

Author Comment

by:addady
ID: 2741237
This question has a deletion request Pending
0
 

Author Comment

by:addady
ID: 2741239
the comment answer my question
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2741410
This question no longer is pending deletion
0
 
LVL 21

Accepted Solution

by:
tfewster earned 400 total points
ID: 2741412
Glad to hear I could help, but why didn't you just accept my comment as an answer?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question