LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 08-14-2005, 10:57 AM   #1
ewt3y
Member
 
Registered: May 2005
Location: hanoi vietnam
Distribution: mandriva
Posts: 106

Rep: Reputation: 15
tar tar cvf - . | (cd /root/; tar xvf -)


tar cvf - . | (cd /root/; tar xvf -)
Plz explain what hyphen and dot symbols mean .
 
Old 08-14-2005, 11:30 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
The periods or dots indicate the present working directory.
 
Old 08-14-2005, 11:40 AM   #3
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
- = stdout/stdin

The first hyphen means output goes to stdout. The output is then piped to the second command where tar reads it from stdin. Actually the command can be shortened since "-" is the default:

tar c . | (cd /root/; tar xv )

This is all nicely explained in man tar.
 
Old 08-15-2005, 06:08 AM   #4
ewt3y
Member
 
Registered: May 2005
Location: hanoi vietnam
Distribution: mandriva
Posts: 106

Original Poster
Rep: Reputation: 15
ok so - is stdout.
I still can't understand why the second part is enclosed in ()
 
Old 08-15-2005, 08:02 AM   #5
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally posted by ewt3y
ok so - is stdout.
I still can't understand why the second part is enclosed in ()
Do you even know what this command is doing? Have you even run it yet?
 
Old 08-16-2005, 01:03 AM   #6
ewt3y
Member
 
Registered: May 2005
Location: hanoi vietnam
Distribution: mandriva
Posts: 106

Original Poster
Rep: Reputation: 15
Plz tell me, it isn't very easy to find the meanings of (cd /root tar xf -)
 
Old 08-16-2005, 11:57 AM   #7
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
tar cvf - .
creates a tar archive of the current directory and sends the output to stdout

|
redirects the output to the following command

( )
opens a subshell in which

cd /root/; tar xvf -
is executed: changes to directory /root and unpacks the tar archive that is read from stdin

Now go and read man bash (or whatever shell you are using) and man tar!!!
 
Old 04-29-2007, 09:25 PM   #8
IamSpOOk
LQ Newbie
 
Registered: Jul 2005
Posts: 15

Rep: Reputation: 1
More detail

tar cvf - . | (cd /root/; tar xvf -)

tar = Stands for "tape archive" This is a legacy-name for when mag tape was king of backup.
c = 'create' (as opposed to extract)
v = 'verbose'. You can miss this out but it won't tell you which files are being worked on.
f = means specify a file to use as the device. Remember, everything in linux is a 'file' so
the beauty of linux (and unix) is that what works with a specical file like a tape device
will also work for any file - including an entry in a block-special filesystem or a the special
file stdout which is used next in this case.
- = 'stdout' This is the default output for all programs. It is usually - but not allways the
screen. Typically, stdout is 'piped' to another program for further processing.
. = 'current directory'. Therefore this whole comman is context dependent. You must have done a cd
into the desired directory before executing it.
| = 'redirect stdout' to 'stdin' of the following program.
() = create a new shell. Thus the stdin of the tar command is fed to a new shell. Inside this shell,
you can do a whole load of commands.
cd /root/ = 'change directory (inside this subshell only) to a new place - this is the destination
of the backup)
; = 'end of this line - what follows is a new command as if you pressed RETURN first.'
tar xvf - = 'rn tar again' but this time x means eXtract. 'f' has the same meansing, but this time '-'
means stdin'
 
Old 04-29-2007, 10:28 PM   #9
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
By the way, this command could be rewritten as:
Code:
tar c | tar x -C /root
The -C option to tar specifies what the working directory for that invocation of tar should be.
 
Old 08-04-2011, 08:54 AM   #10
ow1
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
Hello guys...
I use this once in a while - lost my cheat sheet - glad you guys have it as a google hit..

Mater - that's the shortest version I've ever seen - cool...

But you forgot the DOT

tar c . | tar x -C /dir

Thanks again...
 
Old 02-19-2014, 11:55 AM   #11
dominion7
LQ Newbie
 
Registered: Jul 2012
Location: Franklin, IN
Distribution: RHEL 5
Posts: 3

Rep: Reputation: Disabled
tarring then Untarring remotely

Hello all,

I like setting up no password handshaking between servers, such as for a migration, then run the following from any directory. Most of the time I will set up the script to run after hours in cron for each directory I want to move:

tar cf - . | ssh <servername> "cd /path-to-dir; tar xf -"

I hope this helps someone
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a tough question 4 u, problem in extracting tar & tar.gz files p_garg Linux - General 5 11-08-2010 12:02 PM
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 10 02-23-2008 06:40 AM
Tar xvf I get segmentation fault lvt lists ok Help! Bob Ross Red Hat 0 01-27-2004 11:45 PM
.rpms, .tar.gz, .tgz, .src.rpm, & .tar.bz2 whoots Mandriva 10 10-18-2003 01:08 PM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 07:30 AM


All times are GMT -5. The time now is 04:13 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration