why does linux not seem to use file extensions?

BigToque

Lifer
Oct 10, 1999
11,700
0
76
There are so many files in linux that don't have any extensions and I find it to be quite confusing. I never know which file is an executable, which is a document, which is a configuration file, etc.

Why is linux like this?
 

P0ldy

Senior member
Dec 13, 2004
420
0
0
There are file extensions, just not in every folder. .exe, for example, is not set by extension, but file permissions.

Someone more knowledgable than me can elaborate further, but you can also
# file filename
and get a description of the file.

For example, in /usr/sbin,
# file useradd
returns
useradd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, dynamically linked (uses shared libs), stripped
 

Chaotic42

Lifer
Jun 15, 2001
34,880
2,042
126
I like to put

alias ls='ls --color -a'


in my .profile. It changes the colors of files based on their type. Executable files are green, directories are blue, etc.
 

Chaotic42

Lifer
Jun 15, 2001
34,880
2,042
126
Originally posted by: n0cmonkey
Color ls is icky. :p

Short answer: because file extensions suck.

There are many colors in the ls rainbow. Don't be afraid to let your colors shine.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Chaotic42
Originally posted by: n0cmonkey
Color ls is icky. :p

Short answer: because file extensions suck.

There are many colors in the ls rainbow. Don't be afraid to let your colors shine.

I have trouble reading them when they're an abnormal color. White on black is good for me.
 

Varun

Golden Member
Aug 18, 2002
1,161
0
0
Originally posted by: n0cmonkey
Color ls is icky. :p

Short answer: because file extensions suck.

Why do they suck? I can browse to any folder and instantly tell what every single file in that folder is.

 

pcgeek11

Lifer
Jun 12, 2005
22,380
4,999
136
Originally posted by: Varun
Originally posted by: n0cmonkey
Color ls is icky. :p

Short answer: because file extensions suck.

Why do they suck? I can browse to any folder and instantly tell what every single file in that folder is.

10 - 4. !!
 

hopejr

Senior member
Nov 8, 2004
841
0
0
Executables in any UNIX based OS are determined by the permission flag x. Do an ls -l and see the x in the permissions list. It means it can be executed.

Like n0cmonkey said, extensions suck, and are an unfortunate artefact from the DOS days.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Why do they suck? I can browse to any folder and instantly tell what every single file in that folder is.

http://why.dont.jablowme.net/images/nautilus-mime.jpg

I can do the same thing without extensions, yay for smart file browsers and mime-types. Of course most of my files do have extensions though because of compatibility with the less smart OSes. Notice in the screenshot how the top 2 entries have no extension and the 3rd is wrong and yet Nautilus is still smart enough to display the proper icon?

 

bersl2

Golden Member
Aug 2, 2004
1,617
0
0
Why requiring file extensions sucks:
If your OS makes something executable simply because it ends with .exe, or .this, or .whatever, your OS sucks. Thanks to the execute permission bits (and for scripts, the shebang), I can make anything executable, but only when I say so. There's none of this "Oh, let's execute this program from my browser" type of crap.

That said, we do in fact end up using file extensions for most types of complex data. It does help to be able to tell what is what just by looking at the file name. But the difference is, on our systems, file extension is not canonical.

BTW, if not color, then at least using -F in your ls alias is a good idea. It will end the names of all dirs with '/', all executables with '*', and other special files with similar marks. I use both -F and color.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
The main issue I have with file extensions is basicly caused by Windows handling of them.

For example, if you have a file named dangerous.exe and rename it puddin.jpg then for all Windows knows it's a simple little jpeg file and will treat it as such.

change a name from puddin.jpg to puddin.jpg.exe and you have a nice social engineering attack on unsuspecting windows users.

Of course it's very simple to say "don't double click on exe files from unknown sources and have the OS show file extensions at all times", but what about com? or cmd? or...

Any of the following extensions will possibly allow executable code to be run on your system when you double click on them:
ade, adp, bas, bat, cpl, crt, dll, do*, hlp, hta, inf, ins, isp, jsp, js, jse, lnk, mdb, mde, msc, msi, msp, ,mst, pcd, pif, reg, scr, sct, shs, shb, url, vb, vbe, vbs, wsc, wsf, wsh...

And that's not even a full list of extensions, you personally, need to look out for.

Windows XP SP2 solved this problem to a certain extent by keeping track of files in relation to various security 'Zones' buy storing metadata about the places you obtained the files in NTFS's alternative data streams for the various files. (of course this complex feature has been the source of numerious advisories and patches since SP2 has been released like this one)

Then there are work arounds even for that. Patches certainly help, (and are required irregardless of what OS your using). If your in a corporate enviroment and have a active directory system setup you can go thru the error prone and complex procceedure of systematicly setting pre-aproved execuatable software. You can use ACLs, but that is complex and error-prone itself.

Linux on the other hand has a executable bit in it's permissions model. If it's on, then the files is executable, if it's off, then it's not. Downloaded files are never set to execute, unless they are first extracted from a archive.. and that's never done automaticly either.

There are further UI improvements, also. Like how nautilus will identify mislabled files as such when you try to open them. Also it will not automaticly execute files with misleading names, even if they are set to be executable.

So you see if I take a shell script, and name it .jpg, it won't execute from my file manager even if it's set to be executable..

so Linux can and does pay attention time to time about the file extension. In order for the file to be run I either have to name it something nautilus likes or run it from a command line.

Windows does to mime detection to a certain extent. But only realy impliments it in Internet Explorer when your browsing.

Maybe for Longhorn this situation will improve. Something to look forward to with the next OS, I guess.

Of course for Linux it's not perfect either, but it's nice enough I use it. Also I get snazzy pre-view images for jpegs and such that are automaticly generated. Also I can get thumnails of audio for audio files and it will extract a frame or two from video files for their icons, too. Of course this depends all on what file manager your using, the newness of the distro, and other things like that.

For more information on mime types there is a set of standardized rules by the IANA that keep track of mime types and how to use contents (and yes occasionally file extensions) to determine as accurately as possible the actual file type.

You can find the standards here
and here

Realy Microsoft knows all this. The file extension is a legacy thing left over from DOS days. They never changed it becuase it's what people are used to and MS works very hard to keep familar interfaces and concepts from OS to OS.
 

Vadatajs

Diamond Member
Aug 28, 2001
3,475
0
0
Originally posted by: n0cmonkey
Originally posted by: Chaotic42
Originally posted by: n0cmonkey
Color ls is icky. :p

Short answer: because file extensions suck.

There are many colors in the ls rainbow. Don't be afraid to let your colors shine.

I have trouble reading them when they're an abnormal color. White on black is good for me.

So what's the easy way without color?

ls -l | grep r.x | egrep -v "dr.x|lr.x" | awk '{print $9}' for executables?

Too much typing, I'll take color any day.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Vadatajs
Originally posted by: n0cmonkey
Originally posted by: Chaotic42
Originally posted by: n0cmonkey
Color ls is icky. :p

Short answer: because file extensions suck.

There are many colors in the ls rainbow. Don't be afraid to let your colors shine.

I have trouble reading them when they're an abnormal color. White on black is good for me.

So what's the easy way without color?

ls -l | grep r.x | egrep -v "dr.x|lr.x" | awk '{print $9}' for executables?

Too much typing, I'll take color any day.

ls -F
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: n0cmonkey
ls -F
Is there an easy way indicate symlinks? One of the little things that annoyed me about OpenBSD was that ls had no colour options, but then I didn't bother to look hard enough to find "ls -F" either :p
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: kamper
Originally posted by: n0cmonkey
ls -F
Is there an easy way indicate symlinks? One of the little things that annoyed me about OpenBSD was that ls had no colour options, but then I didn't bother to look hard enough to find "ls -F" either :p

I'm not sure. color ls is in colorls package, I think. Colors are icky. Think of OpenBSD not having color ls as a feature.
 

cquark

Golden Member
Apr 4, 2004
1,741
0
0
Originally posted by: kamper
Originally posted by: n0cmonkey
ls -F
Is there an easy way indicate symlinks? One of the little things that annoyed me about OpenBSD was that ls had no colour options, but then I didn't bother to look hard enough to find "ls -F" either :p

Many systems default alias ls to "ls -sF" and ll to "ll -alF", so it's usually an easy option to discover. The -F option will indicate symlinks with a terminal "@" and in combination as "-lF" will show you an arrow followed by the file that the symlink points to.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: cquark
Originally posted by: kamper
Originally posted by: n0cmonkey
ls -F
Is there an easy way indicate symlinks? One of the little things that annoyed me about OpenBSD was that ls had no colour options, but then I didn't bother to look hard enough to find "ls -F" either :p

Many systems default alias ls to "ls -sF" and ll to "ll -alF", so it's usually an easy option to discover. The -F option will indicate symlinks with a terminal "@" and in combination as "-lF" will show you an arrow followed by the file that the symlink points to.

Systems or distributions? I think I've only seen Linux distros do that by default.
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
How do Linux Desktop Environments handle file associations, i.e. I double-click on a JPEG file and my picture editor opens?
 

cquark

Golden Member
Apr 4, 2004
1,741
0
0
Originally posted by: Stefan
There are so many files in linux that don't have any extensions and I find it to be quite confusing. I never know which file is an executable, which is a document, which is a configuration file, etc.

Why is linux like this?

Different operating systems can be confusing, especially the second one you learn.

File extensions are a quick hack to handle file metadata. However, like many quick hacks, file extensions have substantial drawbacks, some of which have been listed in this thread.

1. There is no necessary association between extension and filetype. You can change the file extension to whatever you want regardless of the file's actual type, which leads to regular users making their files unusable by renaming them and allows attackers to trick users into running trojan horse programs.

2. There are many, many filetypes. It's difficult for regular users to remember them all, especially to recall the more than a dozen executable file extensions, which is another common source of security attacks. Since executability is in the ACL (another type of file metadata), why not use it anyway?

The UNIX "file" command will reliably show you the type of any file, and modern UNIX file browsers will show you filetypes without need for extensions too.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I'm not sure. color ls is in colorls package, I think. Colors are icky. Think of OpenBSD not having color ls as a feature.

How can you dislike color? Are you color blind or something?

How do Linux Desktop Environments handle file associations, i.e. I double-click on a JPEG file and my picture editor opens?

By default jpgs are associated with just a viewer I believe, but the general idea is right. I don't know about Konquerer, but Nautilus will get the file-type right even if the extension is wrong or missing because it actually looks at the file's contents to figure out what type of file it is. Yes, it slows down directory listings a bit but IMO it's worth it and if you have a fast enough drive it's hardly noticable.
 

hopejr

Senior member
Nov 8, 2004
841
0
0
Colour is good imho, and I have anti-aliasing on my Terminal window in OS X too. :p It's white on black and semi-transparent. lol
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Nothinman
I'm not sure. color ls is in colorls package, I think. Colors are icky. Think of OpenBSD not having color ls as a feature.

How can you dislike color? Are you color blind or something?

I have had trouble reading some of the colors. The white on black or black on white is just easier to read.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I have had trouble reading some of the colors. The white on black or black on white is just easier to read.

I can understand that, some of the colors (like blue and cyan) look like they bold the text too making them a little bit blurry when compared to the straight white text. But saying that OpenBSD's ls not having color as an option is a feature would be like X forcing you to run 800x600 because it's easier to read and calling that a feature.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Nothinman
I have had trouble reading some of the colors. The white on black or black on white is just easier to read.

I can understand that, some of the colors (like blue and cyan) look like they bold the text too making them a little bit blurry when compared to the straight white text. But saying that OpenBSD's ls not having color as an option is a feature would be like X forcing you to run 800x600 because it's easier to read and calling that a feature.

I'm just joking. Color is available if you want it, in the colorls package. ;)