LinuxQuestions.org
Help answer threads with 0 replies.
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 11-13-2013, 11:04 AM   #1
gaspower
LQ Newbie
 
Registered: Dec 2005
Posts: 10

Rep: Reputation: 0
Help Using The Tar Command


Hello,

Need a little help with the Tar command. Just need to make sure what I have listed below is going to do what I need.

tar -pcvjf backups/tarbackupname.$DATETIME.tar.bz2 html/ > /dev/null 2>&1

Directory structure

/home/virtual/site1/var/www/html/(all the web files and directories)

I would like to tar all files and folders from the html directory and down. Also want to keep the file permissions, which I think is the -p?

Where I get lost, if I want to tar all files and folders under html/, do I run the command in the html folder, or one above in the www folder. Also, which ever folder I do run the command, I would like the tar file to be created in that folder where it is executed.

Thanks JR
 
Old 11-13-2013, 11:23 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Quote:
Also want to keep the file permissions, which I think is the -p?
This would seem to be a correct assumption based on the man page entry.
Quote:
if I want to tar all files and folders under html/, do I run the command in the html folder, or one above in the www folder.
You can run tar from anywhere, the difference being that where you are will then change how much of the path to the location you need to enter.
So with your current example, because you use 'html/' you would need to be in the directory directly above as this is a relative path as opposed to an absolute one
which starts at root (/) down to location.
Quote:
Also, which ever folder I do run the command, I would like the tar file to be created in that folder where it is executed.
If that is the case then why do you place the backups directory name in front of the tar file name? Remember that tar will not create a directory (that I know of)
 
Old 11-13-2013, 02:50 PM   #3
mddnix
Member
 
Registered: Mar 2013
Location: Bengaluru, India
Distribution: Redhat, Arch, Ubuntu
Posts: 498

Rep: Reputation: 137Reputation: 137
@gaspower

You can run tar command from anywhere you like as long as path at where you want to save tar file and path of which you want to take backup are correct. Just keep in mind that when you want to restore (untar) them, where do you want to put those files (the one you backed-up)... does matter.

Generally, when you want take backup of system files, and you want to restore them at the place where they originally belonged, then tar them with absolute path.
Other than this, if you want to take backup of files/folders and want to restore them in which-ever folder you like, then tar them with relative path.

please refer http://www.linuxquestions.org/questi...2/#post4997953

Original Source: Beginning the Linux Command Line - Sander van Vugt. Page 57.
 
  


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
cygwin simple tar command fails when issues on command line deannad Linux - General 1 06-12-2013 11:22 AM
[SOLVED] LFS 7.3--> tar xf lfs-bootscripts-20130123.tar.bz2 , bash : tar : command not found AkiraMizuki Linux From Scratch 3 06-01-2013 04:00 AM
[SOLVED] command for tar'ing multiple sub-directories into a single tar file blainemiller Linux - Server 3 04-21-2011 03:05 PM
where is TAR ? bash: tar: command not found Juicyapple Linux - Newbie 7 06-10-2009 09:32 AM
tar-command not found while compiling glibc-libidn-2.7.tar.bz2 of lfs6.3 aditya_gpch Linux From Scratch 1 05-14-2008 12:27 AM


All times are GMT -5. The time now is 04:01 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