• United States
Unix Dweeb

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

Nov 21, 20236 mins

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

Learning, computer and training business interns in night office with manager, boss and leadership help. Men with technology planning ideas, kpi strategy and marketing innovation vision with mentor
Credit: - Yuri A / Shutterstock

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.

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.

A brief cheat sheet

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

Getting familiar with your account

Command Function Example
pwd display current file system location pwd
whoami display username whoami
who list logged in users who
ls list files in current location ls; ls -l; ls -a
env display settings (search path, command history ...) env
echo repeat the argument provided echo hello; echo $PATH
history list recently used commands history; history | tail -5
passwd reset your password passwd

Looking at text file content

Command Function Example
cat display file content cat myfile
more view file content a page at a time more myfile
less display file content a page at a time, allows backing up less myfile
head show top of file head myfile; head -5 myfile
tail show bottom of file tail myfile; tail -3 myfile

Managing your files

Command Function Example
chmod change file permissions chmod a+x myscript; chmod 700 myscript
cp make a copy of a file cp myfile savefile
mv rename a file or move to another location mv file oldfile; mv script bin
rm delete a file rm oldfile

View running processes

Command Function Example
ps show processes associated with your current login ps
ps -ef show processes running on the system ps -ef; ps -ef | more

Command output

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.

$ env
LESSOPEN=||/usr/bin/ %s


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

$ echo date: `date`
date: Tue Nov 20 02:53:43 PM EST 2023

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:

$ echo date: `date` > myreport
$ cat myreport
date: Tue Nov 20 03:06:33 PM EST 2023

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:

$ history | tail -3
   84  echo date: `date` > myreport
   85  cat myreport
   86  history | tail -3

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.

$ passwd
Changing password for user justme.
Current password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.


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.

$ more -n 5 TZs

head and tail

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.

$ head -n 5 TZs
$ tail -n 5 TZs


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:

$ chmod 755 myscript

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.

$ chmod 755 mkTable
$ ls -l mkTable
-rwxr-xr-x. 1 justme justme 701 Nov 17 14:05 mkTable


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.

$ cp myfile myfile.backup

mv and rm

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:

$ mv myreport oldreport
$ mv myscript ~/bin
$ mv myreport /shared/reports

The rm (remove) command deletes a file.

$ rm oldfile
$ ls oldfile
ls: cannot access 'oldfile': No such file or directory

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.

$ ps
    PID TTY          TIME CMD
   6688 pts/1    00:00:00 bash
   7201 pts/1    00:00:00 ps

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.

$ ps -ef | grep sshd
root         782       1  0 Nov20 ?        00:00:00 sshd: /usr/sbin/sshd -D
root        6632     782  0 14:38 ?        00:00:00 sshd: shs [priv]
justme      6678    6632  0 14:38 ?        00:00:00 sshd: shs@pts/1
justme      7228    6688  0 16:14 pts/1    00:00:00 grep --color=auto sshd

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.

$ who
fedora   seat0        2023-11-16 09:06 (login screen)
fedora   tty2         2023-11-16 09:06 (tty2)
justme   pts/1        2023-11-17 14:38 (


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.

Unix Dweeb

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.

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.

More from this author