Solved

ýTAR only one directory levelý

Posted on 2000-04-20
5
277 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 20

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 20

Expert Comment

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

831 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