tel2
asked on
How to tar these dirs?
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.
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.
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.
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.
tar -c -f archive.tar -C / home (home being the top directory in question)
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.
As you wrote in your question - you need something more: another tar command or find.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks oklit!
Nice work.
Nice work.
tar -cvf mytar /dir1 /dir2 /dir3
I did not try tar with ~/dirname but I think it should work