Back in 1991, an unassuming computer science student named Linus Torvalds handed in his master’s thesis and accidentally changed the world. His thesis, titled “Linux: A Portable Operating System,” described an operating system that wasn’t just slick and simple to use, but also had a very high throughput, which means that it was able to process lots of information in a small timeframe. So efficient it was, in fact, that it’s still in wide use today.
Linux has, since its inception, been used by almost every software company in some way, shape, or form, and more or less every software product. Literally all of the world’s top 500 supercomputers run Linux, and it’s even running in space.
Yes, Windows fans, you read that right: Linux is much faster than Windows. And before MacOS users start complaining: No, MacOS and Linux are not the same. MacOS is a proprietary system that integrates deeply with Apple hardware and lends itself to the Apple ecosystem; Linux is an open-source system that runs on any desktop. But you can still use many of the Linux commands listed below on your Mac.
Whether you’re a newbie to Linux who’s trying to learn the basics or a seasoned developer who wants a quick knowledge refresher, here’s a list of the commands you’ll need to control a Linux computer.
Note that letters behind a minus sign refer to options of a command. You can combine different options as you please unless they directly contradict each other.
If you need more information about a command, you can access the manual by typing man command (replacing “command” with what you need) in your Linux terminal.
Linux Commands Cheat Sheet
- File and directory navigation commands.
- System information commands.
- File permission commands.
- Hardware information commands.
- File and directory compression.
- Environment variable commands.
- User management.
- Networking commands.
- Process commands.
- Bash shortcuts.
- IO redirection.
- Pipes and command lists.
- Screen shortcuts.
File and Directory Navigation Commands
System Information Commands
File Permission Commands
Every file can, in principle, be read, written, or executed. Whether this is allowed depends on your permissions. Generally, one can set permissions for the user, the group, and for other people.
You can always view the current permissions of files in your directory using ls
-l. You will see a string of letters and symbols that specifies these permissions, for example,
drwxr-xr-x. The first entry specifies whether this is a directory. If yes, there is a
d, otherwise a
The next three entries specify the permissions of the user (usually you). If you’re allowed to read the file or directory, you will see an
r at the second entry; if you’re allowed to write to it, you’ll see a
w at the third entry; if you’re allowed to execute it, you’ll see an
x at the fourth entry. If you do not have one or several of these permissions, a
- will fill the spot instead. The same schema is then applied to the group in entries five through seven, and to any other entities in entries eight to 10.
In our example
drwxr-xr-x, we have a directory that the user can read, write, and execute, and that the group and others can read and execute but not write to.
If you want to change the permissions of a file or directory, the
chmod command is your friend. Generally speaking, the syntax is
chmod [ugoa] [-+=] [rwx] [filename]. That is, you can change the permissions of the user with
u, of the group with
g, of the others with
o, or of all three with
ugo. You revoke a permission with
- and add one with
+. If you want to specify only particular permissions, you can list them behind
=; all permissions that are not listed behind
= are revoked for the user, group, or others in question.
For example, I might want to add write permissions for the group to a directory, called
myDirectory, which has permissions
drwxr-xr-x. In that case, I need to type
chmod g+w myDirectory. The result, visible after typing
ls -l, is
drwxrwxr-x. Note that there is no white space between the options
rwx, but there is a white space before the name of the file or directory.
There is another, slightly more compact way to use
chmod as well. Instead of using three different options, one can use numbers. Read, or
r, corresponds to four; write, or
w, corresponds to two; and execute, or
x, corresponds to one. No permissions means zero. One then writes the sum of the present permissions down for the user, group, and others, respectively.
For example, if I wanted to make sure that the permissions of
drwxrwxr-x, I would type:
chmod 665 myDirectory.
Hardware Information Commands
Note that these hardware commands are specific to Linux. Not all of them will work on other UNIX-based systems, such as MacOS.
File and Directory Compression
Environment Variable Commands
Pipes and Command Lists
Famous Last Words
These are not all the Linux commands in the whole wide world. Hopefully, though, this cheat sheet will help you get by 95 percent of the time. Happy coding!