Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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).
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.
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.