Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to tar these dirs?

Posted on 2011-03-07
7
Medium Priority
?
572 Views
Last Modified: 2012-05-11
Hi Experts,

Occasionally I want to backup these kinds of paths to a tar file:
- All files in my home dir (top level only).  I don't care if this includes dirs.
- All files in say ~/abc and it's subdirs, recursively.

How can I do this with a SINGLE tar command?

I know how to do it with find and tar, or 2 tar commands, but I'm wanting to know how I can do it more simply (i.e. a single tar only).

Points for positive working answers only.  If you don't think it can be done, please don't comment.

Thanks.
0
Comment
Question by:tel2
[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
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 35054890
did you try this

tar -cvf mytar /dir1 /dir2 /dir3

I did not try tar with ~/dirname but I think it should work
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 35054913
Hi,

It is not possible to backup only the ifrst level without directories unless you've excluded them exclusively in the command line. However it is possible to backup several directories with a sigle tar command. So the command you're looking for is:

tar --exclude ./dir1 --exclude ./dir2 --exclude ./dir3 -cvzf /tmp/backup.tgz . /dir2

Cheers,
K.
0
 
LVL 17

Expert Comment

by:Sikhumbuzo Ntsada
ID: 35054979
tar -c -f archive.tar -C  / home (home being the top directory in question)

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 23

Expert Comment

by:Maciej S
ID: 35057789
Simple answer: it's impossible with just one tar command (well, actually it is possible, if you are going to accept manually passing all file names in command line :))
As you wrote in your question - you need something more: another tar command or find.
0
 
LVL 12

Author Comment

by:tel2
ID: 35062601
Hi omarfarid,
The problem is, that will not limit the home dir to the top level only.  Have another read of my requirements, especially the 1st bullet point.

Hi KeremE,
That's been my understanding, too.

Hi Santasi24,
See my response to omarfarid, above.

Hi oklit,
That's been my understanding, too.

Hi All,
For months I've been using the --exclude and --no-recursion tar switches, but I've had to have 2 tar commands, (the 2nd appending the 1st tar file), then a bzip2 command to zip the combined tar file.  I was hoping that I could do it in a single (concise) command (tar -jcvf ...), but it seems not.

Despite the fact that I said "Points for positive working answers only.  If you don't think it can be done, please don't comment.", I may be willing to accept an answer which includes a single 'find' and a single 'tar' command, to backup what I have asked for.  Any takers?
0
 
LVL 23

Accepted Solution

by:
Maciej S earned 2000 total points
ID: 35063306

tar cvf arch.tar $(find /your/home -maxdepth 1 -type f) /your/home/abc

Open in new window

0
 
LVL 12

Author Closing Comment

by:tel2
ID: 35063329
Thanks oklit!
Nice work.
0

Featured Post

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

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…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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.:
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.
Suggested Courses

662 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