Executable files extension in linux

File extensions and association with programs in linux

In windows we can associate a file’s extension with programs.
E.g. a file test.pl can be run by the installed Perl interpreter due to the pl extension.
In linux though it needs #!/usr/bin/perl as the first line.
Is this because there is no association between file extensions and programs in Linux?

6 Answers 6

No, it doesn’t mean that. If you have a text-file that has it’s execute-permission set (e.g. chmod a+x somefile ), and the first line of the file is something like

It just tells Unix what program to use to execute the script. If a text-file is marked as an executable (i.e. is a script), Unix will start whatever program is specified in this way, and send the rest of the text-file (the script) to this program. Typically the program specified will be a shell ( /bin/sh , /bin/csh or /bin/bash ), the interpreter for some programming-language (Perl, Python or Ruby) or some other program that executes scripts (like the text-manipulators Awk or Sed).

Usually the «#» specify a comment in many languages, it’s only if the first line begins with «#!» it’s something special. If a file is marked as executable but doesn’t start with a «#!», Unix will assume it’s some kind of binary (e.g. an ELF-executable made by the C-compiler and linker).

In general Unix doesn’t rely on the suffix of files. Many programs neither needs nor automatically adds their typical suffixes, one exception being the compression-programs (like gzip and bzip2 ) which usually replaces the original file with a compressed one, adding a suffix to mark compression-type (these are one of the few programs that complains about incorrect suffix).

Instead the file is identified by it’s content through a series of tests, looking for «magic-numbers» and other identifiers (you can try the command file on some files to test this). This is also used by the file-browsers under GNOME and KDE to select icons and the list of programs to open/edit the file. Here the MIME-type of the file is identified by such tests, then the suitable programs for viewing and editing is found from a list associated to the MIME-type — not the suffix as in Windows.

Since one of the tests would be to check if the first line of a text-file is «#!/something», and then look at what «something» is; you could say for example that #!/usr/bin/perl identified the file as a perl-script — but that is more of a side-effect. Even if the file doesn’t start with a «#!», the tests should be able to correctly identify the file. In any case, it’s the content of the file that is used to identify it, not an arbitrary suffix. As such, endings like .pl (Perl) and .awk (Awk) is purely to help a human user to identify the type of file, it’s not used by Unix to determent type (like the suffixes in Windows).

Читайте также:  What is buffer and cache memory in linux

You can actually make a «script» without the «#!/something», but Unix wouldn’t be able to automatically run it as an executable (it wouldn’t know what program to run the script in). Instead you’d have to «manually» start it with something like perl myscript or python myscript . Many scripts in larger Python and Perl applications will actually not start with «#!/something», as they’re scripts for «internal use» and not intended to be invoked by the user directly.

Instead you’ll start the main script (which does start with a «#!/something»), and then it will pass these other scripts to the interpreter as this script runs.

Источник

What’s the application extension? (aka .exe, .app, etc.)

I’m new to Ubuntu. What’s the application extension for development reasons? I know Windows is mainly .exe and Mac is .dmg or .app. Does Linux have an unique one?

Incidentally, Mac OS X actually under the cover works the same way as Linux — the fact that a file is executable depends from it being marked with the «executable bit». .app normally aren’t executables, they are camouflaged directories that constitute the application bundle; also, .dmg files are more like installation packages (a .deb on Ubuntu and other Debian-derived distros, .rpm on other distros, .msi on Windows).

4 Answers 4

In general, in Linux, and so in Ubuntu, the applications do not have extensions. Some examples: nautilus , firefox , gnome-terminal , and so on.

Applications are usually located in these directories /usr/local/sbin , /usr/local/bin , /usr/sbin , /usr/bin , /sbin , /bin , /usr/games , /usr/local/games and others.

You can determine whether a file can be an application if and only if that file is executable. Use ls -l filename , or stat filename , or file filename to determine this. If that filename have this permissions: -rwxr-xr-x , then that file is sure executable.

ls -l

Extensions are file name suffixes that start with a period. Usually, they are two or three letters long. Linux can read many file extensions used by other platforms. In Linux you usually compile and run a file manually. The file can be a python script or debian software package or even .exe which can be executed using Wine

Читайте также:  How to see open ports on linux

Here is a list of some file extension

.bz2 — compressed with the bzip2 compression utility

.c — C language source code

.conf and cfg — configuration file

.d — directory containing scripts or configuration files

.deb — Debian software package

.gz — compressed using the gzip utility

.rc — run command configuration data

.rpm — Red Hat Package Manager software package

.so — shared object in a dynamic library

.tar — archive created with the tar utility

.tex — text formatted in the TeX or LaTeX formatting language

.sh — Shell script

.pl — Perl Script

In Ubuntu there is no limitation to the extension of the file . The file ending just describes what or how a file is «executed».

For example a shell script ends with .sh , an installer file ends with .deb . .gz for files compressed using the gzip utility . .tar — archive created with the tar files . .bz2 for files compressed with the bzip2 compression utility

As far as comparision with exe of Windows, in Linux nearly all files can be executable or made executable by proper permissions

To check if a file (This is for a file not directory as I remove «-» specifying it) is executable type

ls -al filename | tr -s ' ' | cut -f1 -d' ' | cut -f2 -d- 

You will find a list of 9 elements with the first three specifying the permission for the owner of the file , the next specifying the permission for the groups to which the owner belongs and the last three for others .The ‘x'(the executable bit) in it represents the executable permission.

This is departure from the way Windows treat an executable is by extension , In *nix anything can be executable.

Источник

Default file extension of the executable created by g++ under Cygwin vs Linux

I’ve done most of my work on VisualStudio and don’t have much experience with gcc or g++. When I tried to compile a (ex. aprogram.cpp) this morning on my pc using cygwin, I got (aprogram.exe) when I tried to compile the same thing on my Ubuntu box I got (aprogram) w/o any extension. I am just wondering if someone be kind enough to tell me why. This question is just out of curiosity. 🙂 Thanks in advance! EDIT: (from Jimmy’s comment) g++ under Cygwin defaults to .exe

Seriously, make your title descriptive, like «why is there no extension in the file name of g++’ output?»

8 Answers 8

That’s easy: on UNIX, you don’t need no steenkin’ extensions. In fact, an «extension» like .c is just a convenient naming convention; unlike Windows, the file system sees the file name as one string, .c and all.

Читайте также:  User and group commands in linux

For a really good time, compile a C program with no -o flag at all. Your executable will still show up — named the default name for executables: a.out .

MS-DOS actually stored file names as an 8 character name and a 3 character extension. Windows 95 and up treated the file name as one long string. Unfortunately, old habits can be hard to break. You can still see people using . to mean all files when the correct wildcard is *

Almost — even on NTFS, a final «.» on a filename is ignored/removed (in the same way that case is ignored), for no discernable good reason.

No, a final period is not removed on NTFS. It is removed by the Windows shell (explorer.exe) for no good reason — NTFS as such (i.e. the Microsoft NTFS driver and all alternatives,including ntfs-3g) does not remove anything. Please be clearer.

Actually, it’s pretty fun to mess with NTFS. For example, you can put on a Linux LiveCD, write files called for example NUL , and it will be off-limits to Windows 🙂 Also, you can have mixed upper- and lower-case on NTFS.

It’s just a naming convention. On Unix/Linux, executables don’t have an extension, just an executable bit.

.exe is a windows thing. Unix doesn’t care about extensions. Executability is based on metadata on the file as well as the file’s contents. g++ through cygwin is not really a windows app, so it carries its unix roots with it.

IIRC cygwin g++ actually defaults to .exe extensions, including the default ‘a.exe’ if no -o is given

If you were wondering how to execute the program on UNIX, simply navigate to the folder with your program you wish to execute (aprogram) and type

This will tell the shell you wish to execute ‘aprogram’ in the current directory.

Executables have no extension in the unix world, because they are meant to be executed in the shell. Imagine the following:

That’s ugly! Unix makes use of so-called magic bytes at the start of each file to detect the file-type. For the default binary format, called ELF, there is a 4 byte word 7f 45 4c 46 at the start. That’s not possible for all file formats. Consider C code or Java code. They can both start with comments, and can be made look exactly the same. So you still have to use file-name extensions, and it’s a good thing when used where it’s appropriate.

Источник

Оцените статью
Adblock
detector