How Did 3-bit Binary Get Into My Linux Output?
When you are working with Linux and you enter the ls -l command, you'll be presented with a list of permissions. What on earth does this mean?
LINUX
William Heldman, Ph.D.
3/6/20243 min read
Here’s an interesting thing: If you run the Linux command ls -al from the terminal window, you get some more output than you would if you just ran the ls command by itself. (The -a switch means “all,” which includes hidden files, and the -l switch means “long.”) If you’re working with Linux and you want to know more about it, then you should understand what all those letters in the first column of a long listing output are telling you.
I find it best to think of these 10 characters as bits that are set, as shown in the figure below. with bit 1 starting on the left, and ending with bit 10 on the right. I just whipped this up in Excel so you can readily see what I’m talking about here.
I am looking at the permissions for the boot line, as shown in Figure 1. Bit one has either a ‘d,’ ‘l,’ or a ‘-’ in it. The ‘d’ means “directory.” An ‘l’ means “symlink,” and a ‘-’ means that you’re looking at a file, which is neither a directory nor a symlink, it is simply a file. Some Linux distributions color-code the output, others do not. This screenshot was taken from Kali Linux, which color-codes the ls output.
Because I normally use Windows computers for my work, I like to think of symlinks as somewhat like a Windows shortcut. In Figure 1 above, you can see that a symlink called boot is pointing to the usr directory, which, in turn is pointing to the bin folder: boot → usr/bin. Like a Windows shortcut, the symlink is saying “Hey, if you need to find the bin (binary) files they’re located here in the bin directory, which is inside the usr directory.”
Now we have to think about the next three bits in the line (columns B, C, and D in Figure 2 above) as that of the user that is currently logged on to this computer and is executing the ls -al command. In Figure 2 above, you can see that bits 2, 3, and 4 have “rwx” in them, respectively. The ‘r’ means “read,” the ‘w’ means “write,” and the ‘x’ means “execute.” This user has the ability to not only read files, they can write them, and, if there’s an executable file they can start it running. (Note: By default, executables show up in Linux listings with a green color-coding. Not all Linux distributions, mind you, just those that color-code the output.)
An executable is a program that you can run from the terminal window, or double-click to run if you’re looking at the executable while using a Linux file explorer utility.
Well then, what about bits 5, 6, and 7 (columns E, F, and G)? This group of bits represents the file permissions of the group to which the user currently belongs. If someone else were in the group that the current user is in (Linux groups and users are another story for another time) they would only be able to read and execute, but they could not write. This means that they could not create files or directories in the current directory, nor can they delete them. They could only list them or run a executables if they found them.
Finally, bits 8, 9 and 10 (columns H, I , and J) represent what they call “the world.” This represents all the other users that are not a member of the group in which this current user is a member. As you can see from Figure 2 above, they too have read and execute rights, but they do not have write permissions.
You can read the rest of the article (complete with graphics) on my Medium page.