Solved

How to tar these dirs?

Posted on 2011-03-07
7
555 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 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 recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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