Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tar command: what is dash for? [closed]

Tags:

linux

shell

tar

Can someone help me understand this command:

tar -czf - -T ./tarFileList.tmp -C ./test_folder/ | ssh -l musthero voserver95.myserver.com -x "umask 002; cd /disk0/test_untar/ ; tar -xzf - "

In particular, I can't understand what is the first dash for (tar -czf - ...).Why do I need it if I have specified list of files I would like to tar (i.e. -T ./tarFileList.tmp), and a directory where to take those files from (i.e. -C ./test_folder/).

Also copying is a bit confusing too - how the tarball gets copied over ssh if there is no cp/scp command?

like image 646
musthero Avatar asked Jun 06 '14 10:06

musthero


1 Answers

The very first dash is unnecessary, you could equally write:

tar cvf ...

The second dash belongs with the f option and it says "instead of creating a named file in the filesystem, write the tarred up files onto stdout".

That stdout is then passed through the pipe into ssh. The corresponding untar on the remote machine is untarring from its stdin in exactly the same way.

So, in answer to your question, the dashes mean stdout when creating/writing a tarfile with tar cf and stdin when extracting/reading a tarfile with tar xf

like image 68
Mark Setchell Avatar answered Oct 15 '22 00:10

Mark Setchell