LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-23-2003, 08:58 PM   #1
rkircher
LQ Newbie
 
Registered: Feb 2003
Posts: 10

Rep: Reputation: 0
How to identify a tar file?


Is there a way to identify a tar file that does not have a tar extension in the virtual console like the bash shell? The file did not have a .tar extension. I tried ls -al and it just says it is a file (-) and that it is executable. Naturally it would not run when I tried. I accidentally saw the same file in the KDE GUI using Konqueror and it clearly identified it as a tar file. How did Konqueror determine it was a tar file?
 
Old 02-23-2003, 09:06 PM   #2
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Konqueror may have given it the wrong icon, I've seen this before on many platforms. I would try:

-t or --list flag on your tar command like, "tar --list filename" But if tar spits out an error you may not have a tar file or it's a currupt tar file.

What extension does it have?
 
Old 02-23-2003, 09:33 PM   #3
rkircher
LQ Newbie
 
Registered: Feb 2003
Posts: 10

Original Poster
Rep: Reputation: 0
My question may not have been clear. Konqueror properly identified it as a tar file. I am asking how to identify a tar in the bash shell. I downloaded a tetris game that had a gz extension. I gunzipped it and the file tetris (no extension) appeared and looked like an executable according to the ls -al command that showed it was an executable file however it would not run. I gave up puzzled. Then later, I accidentally saw it with Konqueror and it identified it as a tar file. Then I went back to the bash shell and used tar -x to untar it and found that it actually was a tar file because it untarred successfully. I always thought that one could do anything in the bash shell and the GUI was icing on the cake, but this proved me wrong. Anyway, I thought I'd ask and see if someone knew how to identify a tar file using just the bash shell and all its commands.
Tnx for reply.
 
Old 02-23-2003, 10:24 PM   #4
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Well what permissions does this file have?
It will not execute unless it is 755.
 
Old 02-23-2003, 11:05 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I tried looking on Google for "tar file format", "tar spec", and a few other choice phrases, but came up empty. I would imagine the first couple of bytes would be a signature of some sort (i.e. what version of tar created the file, or something similar). I'd find it hard to believe that Konqueror would be in the habit of reading the first handful of bytes for each file in the directory you're browsing... I've seen worse though. I'll give it another shot later.

If you can't find anything either, I'd suggest breaking down and taking a look at tar's source code for the answer.

Now, to get that indication from a terminal window, you'd need your own version of ls to check for that signature when it presents the listing. Rather than modifying the ls source code, you could write a script.

However, as far as I know, there is no quick and dirty way of determining what type of data a file contains without actually reading some of it (assuming the extension is missing or ignored).
 
Old 02-23-2003, 11:12 PM   #6
rkircher
LQ Newbie
 
Registered: Feb 2003
Posts: 10

Original Poster
Rep: Reputation: 0
The permissions are 755. There were no error messages when I tried to execute it. It just went off and tried to do something but there were no results of any kind. I don't think tar files can be executed even with the 755, there probably is nothing to execute in the file, but I don't know. That was part of what confused me. Maybe I'll just randomly different things next time like trying to untar it. I still think there must be a way to tell because Konqueror was able to determine what it was somehow. The game file was downloaded from http://linuxbag.com and was tetris.gz I unzipped it and it contained tetris (no extension). I cud not tell that it was a tar file.
tnx helping again.
 
Old 02-23-2003, 11:31 PM   #7
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Here's a link to the tar header format.

Tar file information

I have a feeling that what you'd like to do is more complicated than it's worth, but just in case you want a challenge...
 
Old 02-23-2003, 11:54 PM   #8
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Type the following at the command prompt:

Code:
file filename
where filename is the name of the file you are interested in.

Almost every file contains a couple bits of identifying information at
the very start of the file. This "magic number" is used to identify
files by their content rather than their name. This is the only sane
way of file identification, and has been practiced by reasonable
OS/filesystem/system people forever.
There is a file in /etc called magic. This contains the information
necessary for the "file" command to figure out what the filetype is.

Code:
man file
man magic

Last edited by moses; 02-23-2003 at 11:59 PM.
 
Old 02-24-2003, 09:28 AM   #9
rkircher
LQ Newbie
 
Registered: Feb 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks Moses. You restored my faith that everything is possible from the bash command line. The GUI is great for Newbies like myself until all the resources and commands of Linux are learned. Also thanks to all that replied, it got me digging and learned a lot. --rkircher
 
  


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
is it possible to identify the kind of file descriptor? Thinking Programming 2 08-11-2005 05:43 AM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
tar -cvzf file.xml file.tar.gz RickHunter_Ve Linux - Software 1 10-06-2004 12:58 PM
problem unzipping a tar.bz2 file tar: Error is not recov jyome Linux - Software 4 09-04-2003 01:04 PM

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

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