LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   what's find the extention of a file in linux? (https://www.linuxquestions.org/questions/linux-general-1/whats-find-the-extention-of-a-file-in-linux-295653/)

mcshen 02-27-2005 08:03 PM

what's find the extention of a file in linux?
 
hi,

Is there a program in linux that will give me the extention of a file?

Thanks in advance.

tsphan 02-27-2005 08:18 PM

try "file thisfile.ext"

replace thisfile.ext with your file

it should tell you alot about the file

mcshen 02-27-2005 08:24 PM

ah, great.!
Thanks

michaelk 02-27-2005 08:27 PM

What do you mean by "give me the extension of a file"

Do you want a command to separate the extension from a filename?

Actually file extensions are a just a convenience in linux.

mcshen 02-27-2005 08:36 PM

I mean what command will separate the extension from a filename?. I know file gives me tons of information about the file. But is there a program that will just give me the extention?

amosf 02-27-2005 09:22 PM

I guess the point is - extensions don't mean anything in linux, exept to the user maybe... Document files, OOo and such, still use the concept, but mainly for the users benifit...

KimVette 02-27-2005 10:14 PM

window managers depend heavily on extensions for file association purposes. Some are smart enough to figure out the file type by the contents, but that is not a reliable method, as with Windows, there is no resource fork (as you have on a Mac), file extension association is possibly the best way for the environment to decide which program should open it.

jmajor 02-27-2005 10:18 PM

try this:
Code:

for i in $(ls); do echo -n "$i: "; echo $i | sed 's/^.*\.\([^.]*\)$/\1/'; done
It does an 'ls' in the current dir '$(ls)' to get some filenames to play with.
For each of those it echos what it is working with and then uses 'sed' to rip off everything after the last '.' and shows that too.

HTH

amosf 02-27-2005 10:23 PM

For icon use, maybe, tho konqeror still knows a OOo file without the extension, etc, tho it may give a generic OOo rather than calc icon... Image files etc still preview and so forth. I don't see the extension as much of an issue IME...

KimVette 02-27-2005 10:38 PM

Quote:

Originally posted by amosf
For icon use, maybe, tho konqeror still knows a OOo file without the extension, etc, tho it may give a generic OOo rather than calc icon... Image files etc still preview and so forth. I don't see the extension as much of an issue IME...
THat's because the KDE framework remembers which app generate the file. Try taking that file to another Linux box, without the extension, and click on it. Try under various window managers - NOT on the same box which created the file.

It's fantastic that konqueror remembers which app created which document, but it's hardly an ideal setup.

--Kim

amosf 02-27-2005 11:12 PM

You are probably right. It's not something I worry over and the apps tend to place extensions accordingly... So for data files the extensions are useful, but not necessary with execuatables...

Actually I'm not sure what KDE does, as you can copy and duplicate given files, trasfer across machines, etc, and KDE still seems to have some idea of what they are, tho not always perfectly. Some sort of file preview, I'd say.

heema 02-28-2005 02:47 AM

you could type :

Code:

file FILENAME | awk '{ print $2 }'

theYinYeti 02-28-2005 08:39 AM

Code:

$ sed 's/.*\.//' <<<"toHTML.php"
php

Yves.

IsaacKuo 02-28-2005 09:39 AM

Quote:

Originally posted by KimVette
THat's because the KDE framework remembers which app generate the file.
No, it's because Konqueror actually examines the contents of a file in to figure what the heck it is, if there's no file extension. If you're using "Icon View" mode, it will do this just to generate the thumbnail.

KimVette 02-28-2005 09:51 AM

Thanks for restating what I already said. However the system isn't perfect - sometimes it cannot figure out the type based on the contents, but can based on the extensions.

Some environments are smart enough to figure it out based on the contents but not all, and of course it will vary depending on which versions of various libraries are installed. Thanks for trying to play semantics though.


All times are GMT -5. The time now is 12:42 PM.