Solved

ýTAR only one directory levelý

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now