LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2013, 11:10 AM   #1
AK139
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
How to Tar/Zip files do a different directory from compression


Hey Guys,

I need some help with backing up files.
My folder I want to backup is called backup123. The location is /home/Desktop/123/backup123
Instead of backing it up to the folder 123 I want to back it up to the folder /home/Desktop/allbackups
How would I do that.

P.S sorry if you don't undderstand me, my english is not the best.

Thanks,

Ak139
 
Old 07-27-2013, 11:34 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Hi AK. You're English is fine. Just create your tar.gz file normally and move it wherever you like. So if you create it in backup123 you can always move it to the allbackups folder.
ciao,
jdk
 
Old 07-27-2013, 11:42 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,465

Rep: Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069
Or when you specify the name of the file, just give the full path to where you want it.

Instead of
Code:
zip backup.zip file1 file2 file3
do
Code:
zip /home/Desktop/allbackups/backup.zip file1 file2 file3
 
Old 07-27-2013, 12:09 PM   #4
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
There are basically two ways to make tar file, one with absolute path and other with relative path. When you want to backup some files, and later you want to restore them where they were, then use tar with absolute path. If you want to extract tar to any location, then create tar with relative path.

Tar with absolute path:
Code:
$ tar -cvf backup.tar /home/Desktop/123/backup123
Tar with relative path: (Notice -C and '.' at the end)
Code:
$ tar -cvf backup1.tar -C /home/Desktop/123/backup123 .
Untar with absolute path:
Code:
$ tar -xvf backup.tar
Untar with relative path:
Code:
$ tar -xvf backup1.tar -C /home/Desktop/allbackups
Note: i have excluded -z or -j option for simplicity.

Last edited by mddnix; 07-27-2013 at 12:10 PM.
 
Old 07-27-2013, 01:16 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,090

Rep: Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474
also depending on just what operating system and what desktop enviroment is being used
you might have a lot of trouble running programs on the "Desktop"
kde4 dislikes that , some of the "activates" will not even allow that
the same gos for some setup of gnome3

linux is not windows
a lot of developers can go out of there way to make sure that a linux Desktop dose not look like a wiundows DE with 100,000,000 folders/launchers/installers/zips/rars/ and so on cluttering it up

the "Desktop" folder is a special case folder , not a normal everyday folder like "Documents" or "Downloads" or "Music"

Last edited by John VV; 07-27-2013 at 01:17 PM.
 
Old 07-27-2013, 01:21 PM   #6
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by John VV View Post
wiundows DE with 100,000,000 folders/launchers/installers/zips/rars/ and so on cluttering it up
LOL... how true.. i've come across such desktops many times...
 
Old 07-29-2013, 06:02 AM   #7
AK139
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
$ tar -cvf backup1.tar -C /home/Desktop/123/backup123 .

So that would tar the file then move it to the location? /home/Desktop/123/backup1223?
 
Old 08-15-2013, 11:10 PM   #8
AK139
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
bumP!
 
Old 08-15-2013, 11:30 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by AK139 View Post
$ tar -cvf backup1.tar -C /home/Desktop/123/backup123 .

So that would tar the file then move it to the location? /home/Desktop/123/backup1223?
No, that would create the backup1.tar in the current directory,
the
-C /home/Desktop/123/backup1223 .

means the files 'in' backup1223/ will be backed up...

BUT if you ask me that is a very nasty antisocial way of using tar

The convention is that when you 'untar' you get a Directory, along with its contents IN the Directory.

to do that here ( and where you want the backup )
Code:
tar -cvf /home/Desktop/allbackups/backup1.tar -C /home/Desktop/123 ./backup123
assuming you have a new(ish) version of tar, you can use the auto compression feature
Sorry, I don't recall which version that started with, not sure I ever knew

Code:
tar -acvf /home/Desktop/allbackups/backup1.tar.xz -C /home/Desktop/123 ./backup123
or
tar -acvf /home/Desktop/allbackups/backup1.tar.bz2 -C /home/Desktop/123 ./backup123
 
Old 08-15-2013, 11:36 PM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,270
Blog Entries: 1

Rep: Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304
Quote:
Originally Posted by AK139 View Post
$ tar -cvf backup1.tar -C /home/Desktop/123/backup123 .

So that would tar the file then move it to the location? /home/Desktop/123/backup1223?
No, that would tar the file in the local directory, but preserve the full paths of the tarred files.

To answer your first question (IIRC)...
Code:
tar -cvf /home/Desktop/allbackups/backup123.tar Desktop/123/backup123/
Should do it.

Last edited by astrogeek; 08-15-2013 at 11:37 PM. Reason: typos
 
Old 08-15-2013, 11:42 PM   #11
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by astrogeek View Post
No, that would tar the file in the local directory, but preserve the full paths of the tarred files.
has the Change Dir ( -C )

so it was like

Code:
cd /home/Desktop/123/backup123
   tar cvf $OLDPWD/backup1.tar .
cd $OLDPWD
 
1 members found this post helpful.
Old 08-15-2013, 11:45 PM   #12
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,090

Rep: Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474
If for some reason you do NOT want to use the built in tools in your Desktop Manager ( KDE4 or Gcome3, lxde,... )
there should be an option on the r-click menu to compress the folder
r-click on the folder and look in the menu
there should be an option ( just like there is on windows -- the SAME type of options )

you can also do it is a few steps instead of one
-- using zip , for the help options use
Code:
zip --help
try this
Code:
cd ~
zip -r allbackups.zip /home/Desktop/allbackups
mv ~/allbackups.zip /home/Desktop/123/backup123
however that folder location you posted dose not make sense
the layout is ALL WRONG
/home/Desktop
is the HOME folder for the USER called "Desktop"

you do not login as the user called Desktop ?
and the user name "Desktop " is not your user name , is it ?

it should be something like this
" /home/AK139/Desktop/allbackups "
with the user name you login with "AK139"
 
Old 08-16-2013, 12:15 AM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,270
Blog Entries: 1

Rep: Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304
Quote:
Originally Posted by Firerat View Post
has the Change Dir ( -C )

so it was like

Code:
cd /home/Desktop/123/backup123
   tar cvf $OLDPWD/backup1.tar .
cd $OLDPWD
Ah, you are correct - I missed the -C.

But still, as I read the OP's original question, they are asking about how to get the archive file saved in a different location, so this should do that, with the effects of -C removing the parent directories from the archived paths...

Code:
tar -cvf /home/Desktop/allbackups/backup123.tar -C /home/Desktop/123/backup123/
So, to be clear, the above would archive the contents of /home/Desktop/123/backup123/, and save the archive to /home/Desktop/allbackups/backup123.tar. This would work from any place in the tree.
 
Old 08-16-2013, 12:32 AM   #14
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by astrogeek View Post
Code:
tar -cvf /home/Desktop/allbackups/backup123.tar -C /home/Desktop/123/backup123/
So, to be clear, the above would archive the contents of /home/Desktop/123/backup123/, and save the archive to /home/Desktop/allbackups/backup123.tar. This would work from any place in the tree.
Yes,
But that is the problem for me, the contents not being archived within a directory

just a space fixes it
Code:
/123/  backup123/
but it might be just me who hates tars that have a tonne of content 'in root'
always seems to be when I didn't bother with tar tf, or making a temp dir.
 
Old 08-16-2013, 12:35 AM   #15
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,270
Blog Entries: 1

Rep: Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304Reputation: 2304
Quote:
Originally Posted by Firerat View Post
Yes,
But that is the problem for me, the contents not being archived within a directory

just a space fixes it
Code:
/123/  backup123/
but it might be just me who hates tars that have a tonne of content 'in root'
always seems to be when I didn't bother with tar tf, or making a temp dir.
Actually I happen to agree with that - I hate opening a tarball and having it dump everyting into the working directory! But,that is what -t is for

But that was not the OP's question so I ignored it, along with the apparently mangled paths noted by JohnVV.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to zip files from a directory into seperate files firespydr Linux - General 5 09-09-2011 10:07 AM
where (which directory) to install linux pakage (tar.gz, .zip) ? amritpalpathak Linux - Software 6 10-20-2010 01:24 PM
Problem sending .tar files, turns into a .zip?Why? Ank_with problems Linux - Newbie 3 07-01-2009 03:12 AM
Help!! how to password protect tar and zip files pnmanojshenoy Linux - Newbie 3 07-08-2008 01:18 AM
Tar/Zip Files and Such Godboo Linux - Newbie 2 01-10-2004 04:33 PM


All times are GMT -5. The time now is 11:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration