Solved

ýTAR only one directory levelý

Posted on 2000-04-20
5
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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 how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

690 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