Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a *nux newbie and I have some doubts regarding *nix.

  • I don't know which type of executable file is ls, whether it is .sh or .ksh or any other kind of system executable if it is, what is that?

  • when I tried to see what is the source code of ls command looks like, it shows something unreadable, what method does *nix use to create these types of unreadable files and can I make my files similar to these files (like ls - unreadable).

share|improve this question
2  
2  
I think it's more related to the URL above than it's a dup. –  slm 6 hours ago
add comment

2 Answers

You can determine the nature of an executable in Unix using the file command and the type command.

type

You use type to determine an executable's location on disk like so:

$ type -a ls
ls is /usr/bin/ls
ls is /bin/ls

So I now know that ls is located here on my system in 2 locations:/usr/bin/ls & /bin/ls. Looking at those executables I can see they're identical:

$ ls -l /usr/bin/ls /bin/ls
-rwxr-xr-x. 1 root root 120232 Jan 20 05:11 /bin/ls
-rwxr-xr-x. 1 root root 120232 Jan 20 05:11 /usr/bin/ls

Using file

If I query them using the file command:

$ file /usr/bin/ls /bin/ls
/usr/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x303f40e1c9349c4ec83e1f99c511640d48e3670f, stripped
/bin/ls:     ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x303f40e1c9349c4ec83e1f99c511640d48e3670f, stripped

So these would be actual physical programs that have been compiled from C/C++. If they were shell scripts they'd typically present like this to file:

$ file somescript.bash 
somescript.bash: POSIX shell script, ASCII text executable

What's ELF?

ELF is a file format, it is the output of a compiler such as gcc, which is used to compile C/C++ programs such as ls.

In computing, the Executable and Linkable Format (ELF, formerly called Extensible Linking Format) is a common standard file format for executables, object code, shared libraries, and core dumps.

It typically will have one of the following extensions in the filename: none, .o, .so, .elf, .prx, .puff, .bin

share|improve this answer
 
@lgeorget - See this Q&A for tips on using type vs. which: unix.stackexchange.com/questions/85249/…;. It's generally best to just use type anywhere you're tempted to use which or whereis. –  slm 5 hours ago
2  
Additionally, for GNU tools, the source code is freely available, start your search at gnu.org/software –  glenn jackman 4 hours ago
add comment

It is a binary executable (compiled into machine code, like most of the system). Shell scripts are more like "glue" to join parts together to quickly and flexibly create solutions out of existing stuff. That's the power of *nix.

You need the source code (c, sometimes c++, are the most common languages on *nix), not just the compiled executable. As it is open source, you can get the code for everything from online repositories (core utilities are usually from the gnu project). However, it's a bit tricky if you don't know how to use git or other version tracking systems.

Here is the ls.c file, if it helps: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c

share|improve this answer
 
Oh and to clarify the question how to create binary applications: choose among countless programming languages (except for a couple that are interpreted or semi-interpreted, such as python, java, javascript,... which don't traditionally produce a standalone executable binary file). Then learn to use that language and how to compile it. –  orion 6 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.