LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-27-2005, 08:03 PM   #1
mcshen
LQ Newbie
 
Registered: Dec 2003
Distribution: womandrake
Posts: 28

Rep: Reputation: 15
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.
 
Old 02-27-2005, 08:18 PM   #2
tsphan
Member
 
Registered: Jan 2005
Location: Clackamas, Oregon, US
Distribution: Slackware 10.2
Posts: 154

Rep: Reputation: 30
try "file thisfile.ext"

replace thisfile.ext with your file

it should tell you alot about the file
 
Old 02-27-2005, 08:24 PM   #3
mcshen
LQ Newbie
 
Registered: Dec 2003
Distribution: womandrake
Posts: 28

Original Poster
Rep: Reputation: 15
ah, great.!
Thanks
 
Old 02-27-2005, 08:27 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
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.

Last edited by michaelk; 02-27-2005 at 08:29 PM.
 
Old 02-27-2005, 08:36 PM   #5
mcshen
LQ Newbie
 
Registered: Dec 2003
Distribution: womandrake
Posts: 28

Original Poster
Rep: Reputation: 15
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?
 
Old 02-27-2005, 09:22 PM   #6
amosf
Senior Member
 
Registered: Jun 2004
Location: Australia
Distribution: Mandriva/Slack - KDE
Posts: 1,672

Rep: Reputation: 46
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...
 
Old 02-27-2005, 10:14 PM   #7
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
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.
 
Old 02-27-2005, 10:18 PM   #8
jmajor
Member
 
Registered: Nov 2004
Location: Australia
Distribution: Fedora, Ubuntu
Posts: 55
Blog Entries: 2

Rep: Reputation: 17
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
 
Old 02-27-2005, 10:23 PM   #9
amosf
Senior Member
 
Registered: Jun 2004
Location: Australia
Distribution: Mandriva/Slack - KDE
Posts: 1,672

Rep: Reputation: 46
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...
 
Old 02-27-2005, 10:38 PM   #10
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
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
 
Old 02-27-2005, 11:12 PM   #11
amosf
Senior Member
 
Registered: Jun 2004
Location: Australia
Distribution: Mandriva/Slack - KDE
Posts: 1,672

Rep: Reputation: 46
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.
 
Old 02-28-2005, 02:47 AM   #12
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
you could type :

Code:
file FILENAME | awk '{ print $2 }'
 
Old 02-28-2005, 08:39 AM   #13
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Code:
$ sed 's/.*\.//' <<<"toHTML.php"
php
Yves.
 
Old 02-28-2005, 09:39 AM   #14
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,546
Blog Entries: 8

Rep: Reputation: 465Reputation: 465Reputation: 465Reputation: 465Reputation: 465
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.
 
Old 02-28-2005, 09:51 AM   #15
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
.sh install file extention matt Linux - Newbie 7 09-09-2004 03:37 AM
how can we use .so extention in linux and where ? satishpatel Linux - Software 1 04-08-2004 01:00 AM
What is the extention of Linux executable files. AskMe Linux - Newbie 4 10-22-2003 01:55 PM
How do i find the proper linux config file? justinfl General 2 10-08-2003 11:01 PM
unpacking a (.sh) file extention. troycus Linux - Newbie 2 10-07-2003 09:52 PM

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

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