Linux executable file extensions

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).

Читайте также:  Find file cli 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

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

Читайте также:  Установка qemu astra linux

.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.

Источник

What is the extension of output files of gcc operation?

If I do gcc filename.c , I get a.out After performing gcc -o output_name filename.c we get the executable file output_name . What is the extension of this file?

2 Answers 2

Unlike windows, Linux does not depend upon extension of a file to determine what type of file it is. Instead, it will check first few bytes of the file and determine what type of file it is.

Hence the output file given by gcc requires no extension. You may add whatever extension you want(by changing -o output_name to say -o output_name.abcd ), but it is not going to mke any difference.

You can have a look at the output of the command

:~$ file output_file output_file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=9bc9fabf05a3d2e58c7780c48cd873cb2955b2ec, not stripped :~$ 

It does not have one. You can do gcc -o myprog.exe filename.c and it will be called myprog.exe . Unlike Windows there is no default extension for executable files on Linux. If you want to mark a file as executable do chmod +x file .

ls -l shows you if the x (executable) flag is set for your file:

user@host# ls -l filename -rwxr-x--x 1 ubu users 42 Mai 10 08:16 filename - means its a file (d would be directory,see below) r means readable w means writeable x means executable 

The first triple is for the owner ( ubu in this case), the second triple is for the owning group (users) and the last triple is for everyone else.

For directories the x means «can enter directory», so if x is not set you cannot do cd directory .

On Linux File Extensions are not special, the are just part of the files name.

Читайте также:  Linux как сохранить переменную

Источник

Thread: what Executable File in ubuntu and how to run ?

dabyv is offlineSpilled the Beans

Questionwhat Executable File in ubuntu and how to run ?

Executable File in windows is exe
and ubuntu ever have any format like that?
how to run that? double click?

sikander3786 is offlineSimply, Ubuntu Addict!

Join Date Apr 2009 Location Rawalpindi, Pakistan Beans 5,669 —> Beans 5,669 Distro Ubuntu Gnome Development Release

Re: what Executable File in ubuntu and how to run ?

To be exact, .exe equal in Ubuntu is .deb and you can install it by simply double clicking and then follow on-screen instructions.

But, Ubuntu uses repositories, software sources and you can install almost any software without going to different websites and downloading multiple .deb packages. All you need to do is to search for your software in ‘Software Center’ under the Applications menu.

sj1410 is offlineFrothy Coffee!

Re: what Executable File in ubuntu and how to run ?

On Linux, executables don’t have an extension. The files simply have a flag in their attributes to say whether they are executable or not. These files tend not to have an extension, but it doesn’t mean that files with an extension aren’t executable

for example you create a file myexec.sh

mcduck is offlinemmmm. Ubuntu.

Join Date Apr 2005 Location Finland/UK Beans 10,807 —> Beans Hidden! Distro Ubuntu 16.04 Xenial Xerus

Re: what Executable File in ubuntu and how to run ?

The closest equivalent of a Windows .EXE file in Linux would be an ELF file.

But the others are correct in that the only thing that defines an executable file in Linux is the execute permission, and of course if the file has some content that can be executed, be it ELF file or some script that can be executed in some shell (like shell scripts) or interpreter (python scripts, for example).

The file name extensions are mostly just for user’s convenience in Linux, the system itself doesn’t care much about them and instead detects file types by the file’s actual contents, using magic numbers.

dabyv is offlineSpilled the Beans

Re: what Executable File in ubuntu and how to run ?

QuoteOriginally Posted by mcduck View Post

The closest equivalent of a Windows .EXE file in Linux would be an ELF file.

But the others are correct in that the only thing that defines an executable file in Linux is the execute permission, and of course if the file has some content that can be executed, be it ELF file or some script that can be executed in some shell (like shell scripts) or interpreter (python scripts, for example).

The file name extensions are mostly just for user’s convenience in Linux, the system itself doesn’t care much about them and instead detects file types by the file’s actual contents, using magic numbers.

so i have 2 files compiled by my self whit a guid and they dosent any format just 2 file name! and i want to run them and i duoble click on them and nothing changed any idead?

Источник

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