LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09: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, 10:30 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
The periods or dots indicate the present working directory.
 
Old 08-14-2005, 10: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, 05: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, 07:02 AM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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, 12: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, 10: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, 08: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, 09:28 PM   #9
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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, 07: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, 10: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



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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
a tough question 4 u, problem in extracting tar & tar.gz files p_garg Linux - General 5 11-08-2010 11:02 AM
Tar –xvf I get segmentation fault –lvt lists ok Help! Bob Ross Red Hat 0 01-27-2004 10:45 PM
.rpms, .tar.gz, .tgz, .src.rpm, & .tar.bz2 whoots Mandriva 10 10-18-2003 12:08 PM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08: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
Open Source Consulting | Domain Registration