LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 02-24-2016, 07:24 AM   #1
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Rep: Reputation: Disabled
tar -f?


Hi, this might be a stupid question, but I'm trying to find out exactly what the tar command means.

I looked up
Code:
tar -xf
I know the x stands for extracting files, but the f?

Apparently it means "use file archive or device archive".

Can anyone elaborate on that?
 
Old 02-24-2016, 07:40 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
-f requires an additional string to specify what do you want to tar/untar
-f <filename> or -f <device>
 
1 members found this post helpful.
Old 02-24-2016, 07:42 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Not very helpful, but from the tar(1) manual page:
Code:
     -f, --file ARCHIVE
           use archive file or device ARCHIVE
I believe the proper, original naming of the command represents "Tape ARchive".

What tar does, and was originally intended to do, was to concatenate files to put them into one file and then place them onto a physical tape archive ... yeah, "way back when".

Experiment with tar, using no compression and just using, "different, but small, text files". And see what it does. An example:
Code:
~/testcode$ echo ABC > a.txt
~/testcode$ echo 123 > b.txt
~/testcode$ tar -cvf new.tar a.txt b.txt
a.txt
b.txt
~/testcode$ cat new.tar
a.txt0000644000175000017510000000000412663330656011223 0ustar  <mylogin><mygroup>ABC
b.txt0000644000175000017510000000000412663330662011221 0ustar  <mylogin><mygroup>123
~/testcode$
Rather inefficient I'll grant when the files are tiny, but there you have it. And whatever all the junk is between the filename and file contents is beyond me, but some of it appears able to be decoded, such as the 644 appears to be file privileges.
 
Old 02-24-2016, 07:48 AM   #4
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
-f requires an additional string to specify what do you want to tar/untar
-f <filename> or -f <device>
But if I just said

Code:
tar -x <filename>
wouldn't that work?
 
Old 02-24-2016, 07:55 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
have you tried it? See also the man page of tar:
Code:
ENVIRONMENT
     TAPE    Device or file to use for the archive if --file is not specified.  If this environment variable is unset, use stdin or stdout instead.
 
1 members found this post helpful.
Old 02-24-2016, 07:59 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by chris_crunch View Post
But if I just said

Code:
tar -x <filename>
wouldn't that work?
No it would not. The -f specifies the file, otherwise I believe it will be looking at stdin, but could be mistaken.

As offered by pan64, suggest you try these things. Make a test tar file and just try things out.
 
Old 02-24-2016, 08:06 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by chris_crunch View Post
But if I just said

Code:
tar -x <filename>
wouldn't that work?
It's easy enough to try it, but no, that says to extract something named <filename> from the default device, which, depending on what version of tar you have, is either stdin or the (probably nonexistent) tape drive. Starting with version 1.11.5, GNU tar uses standard input and standard output as the default device. Prior versions looked for a TAPE environment variable, or in the absence of that used a compiled-in default device, typically "/dev/nst0".
 
Old 02-24-2016, 08:31 AM   #8
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by chris_crunch View Post
Hi, this might be a stupid question, but I'm trying to find out exactly what the tar command means.

I looked up
Code:
tar -tf
I know the x stands for extracting files, but the f?

Apparently it means "use file archive or device archive".

Can anyone elaborate on that?
So I an example that I use with -f is looking at the content of tar file

Code:
tar -tf example.tar 


./file1/ 
./file2/
./file3/
./file4/
./file5/
 
Old 02-24-2016, 02:15 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by rtmistler View Post
Not very helpful, but from the tar(1) manual page:
Code:
     -f, --file ARCHIVE
           use archive file or device ARCHIVE
I believe the proper, original naming of the command represents "Tape ARchive".

What tar does, and was originally intended to do, was to concatenate files to put them into one file and then place them onto a physical tape archive ... yeah, "way back when".

Experiment with tar, using no compression and just using, "different, but small, text files". And see what it does. An example:
Code:
~/testcode$ echo ABC > a.txt
~/testcode$ echo 123 > b.txt
~/testcode$ tar -cvf new.tar a.txt b.txt
a.txt
b.txt
~/testcode$ cat new.tar
a.txt0000644000175000017510000000000412663330656011223 0ustar  <mylogin><mygroup>ABC
b.txt0000644000175000017510000000000412663330662011221 0ustar  <mylogin><mygroup>123
~/testcode$
Rather inefficient I'll grant when the files are tiny, but there you have it. And whatever all the junk is between the filename and file contents is beyond me, but some of it appears able to be decoded, such as the 644 appears to be file privileges.
They are the user ownership, group assigned, access mask, and dates taken from the inode when the
archive was created. These can be used to restore the file to its original condition. In addition to the minimum, tar has been extended to also include ACLs, and security labels as well.

tar is a backup tool - as such it has to keep many things about the file (the path used when making the
backup is one - so the file name shown is short).
 
  


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 Off
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
[SOLVED] tar -tf down.tar.How to avoid listing subfolders is down.tar e3399 Linux - Newbie 2 11-25-2010 09:28 PM
"Invalid tar magic" error msg. when I try to tar ldmud *.tar file in DSL pixxi451 Linux - Newbie 4 07-04-2010 08:32 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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