Blog

Getting started on the Linux (or Unix) command line, Part 3 | Network World

Our Linux cheat sheet includes some of the most commonly used commands along with brief explanations and examples of what the commands can do.

One of the things you need when building your “chops” on Linux is a command vocabulary that will allow you to do all of the things that you need to do on the command line. One of the best ways to do this is to start with a “cheat sheet” – a list of the commonly used commands with brief explanations and examples of what the commands can do. A cheat sheet can help you to become familiar with commands you might not even have known were available. WPC Production Line

Getting started on the Linux (or Unix) command line, Part 3 | Network World

This post provides an intro Linux cheat sheet. It includes a series of commands with descriptions and examples and categorizes them in groups by their primary focus. Keep in mind that, while most commands on Linux will work the same from one distribution to the next, some commands – like those used to install manage packages (tools, programming languages, etc.) – will differ from one distro to another.

The tables below provides information on some of the most basic Linux commands.

The examples in this section provide sample output for many of the commands described in the tables above.

The env command provides a lot of information on your command environment. This includes the shell assigned to your account, how many of the commands you run will be maintained in your command history (HISTSIZE), your default text editor, your current file system location, terminal type and most recent former file system location as well as other data.

The echo command will display content you provide and variables you include, but it can also be used to add lines to existing files.

Note that including command output in an echo command requires using backticks to run the command rather than just display its name. To add the generated output to a file, you would use a command like this:

Keep in mind that > overwrites and former file content. Use >> to append to an existing file.

The history command shows recent commands you have run – as many as your $HISTSIZE setting allows. You can narrow this down to the most recent four with a command like this:

The passwd command allows you to change your password but requires that you enter your current password first. It also enforces some length and complexity requirements.

The more command displays file content a screen at a time. To save space below, I’ve used the -n option to display only five lines at a time from a very long list of time zones. You would press the enter key to see the next five.

The head and tail commands will display the top and bottom lines in text files. As with the more command, you can add the -n option to limit the number of lines displayed.

The chmod command is used to change file permissions. If you set up a script that you want others to be able to run, you can give them execute permission with command like this:

The first 5 in the chmod command above sets the script’s permissions to allow others in the same group to read and execute the script. The second allows anyone else to run the script (provided they have access to the file’s location). Normally, Linux accounts are set up with the account owner being the only member of a same-named group.

The cp command makes a copy of a file. For example, it’s often a good idea to make a backup copy of a file before making significant changes so that you can easily “roll back” if something goes wrong.

The mv (remove) command allows you to rename a file, move it to another location, or do both in a single command. Here are some examples:

The rm (remove) command deletes a file.

The final ls command above shows that the file is no longer available after the rm command is run.

The ps command shows running processes. Without arguments, it only shows processes related to your current login.

Use ps -ef (ps -aux on some systems) to see all running processes. You can send the command output to a more or a grep command to restrict the output to just what you’re looking for.

The command output above is showing processes associated with the sshd (secure login) processes.

The who command provides a list of everyone currently logged into the system, whether at the system console or logged on remotely.

There’s a lot to learn about Linux before you will likely feel “at home” on the command line, but it’s well worth the effort.

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

Getting started on the Linux (or Unix) command line, Part 3 | Network World

PVC Pipe Line Machine The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.