You probably know by now that on your computer, not everything is as it seems. File types, like those used by Microsoft Excel or Adobe Illustrator, are no exception.
Believe it or not, the onus is on the program (and the user) to recognize its own type of file. There are a few conventions used to keep track, and knowing these conventions will help you understand and succeed on your linux account and on computers in general.
That's right, even text files are binary. It's just that programs that read text files, like more,less,head,tail and nano, expect each binary number to map to printable character in the ASCII character set (or other character sets like UTF-8).
Want to know more? Look behind the curtain.
First off, files that are meant to be run are different than files that are meant to be read, and they come in both text and binary forms.
On linux, text files referred to as “scripts” are executable, meaning they can function like a program. On Linux and Unix, these files start with the “#!” convention in the first line.
#!/bin/bash echo "hello world"
$ ./helloWorld.bash hello world
You can check a text file to see if it's a script with the “head” command, or the “file” command:
$ head -1 helloWorld.bash #!/bin/bash $ file helloWorld.bash helloWorld.bash: Bourne-Again shell script, ASCII text executable
This file actually doesn't need the “.bash” file extension. It is only there to remind us what kind of file it is.
$ mv hellWorld.bash helloWorld $ ./helloWorld hello world $ head -1 helloWorld #!/bin/bash $ file helloWorld helloWorld.bash: Bourne-Again shell script, ASCII text executable
*Just one more extra thing: remember, files must have executable file permissions to be used this way. See wiki:file_permissions
$ ls -l helloWorld.bash -rwxr-xr-x 1 email@example.com firstname.lastname@example.org 31 Jul 13 10:56 helloWorld.bash
Notice the “x” in three different places in that first string “-rwxr-xr-x” See the link above to decipher it.
You can't use the text readers (more,less,head,tail,nano) on these to see what they are, but the file command still works. Let's try it on a program you have already been introduced to:
$ file /usr/bin/ls /usr/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV)
ELF stands for Executable and Linkable Format, which is jargon for a binary program. There is actually more that is returned by this command, but I gave you the 'PG' version.
$ less /usr/bin/ls "/usr/bin/ls" may be a binary file. See it anyway?
The answer is “no”, but type 'y' anyway. You can use the space bar to “scroll”, but it won't look like anything. When it gets to be too much, type 'q'.
So, what gives? Isn't everything binary?