Solved

How to tar these dirs?

Posted on 2011-03-07
7
559 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linux pull logs and export FTP 4 87
UNIX Script. Send email if failure 8 93
Pass stdin text to Python subprocess 3 90
Merging two files with Perl 5 59
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…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
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…

751 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