Glossary of Linux Command Line Tools

Introduction

Working with a terminal can be confusing for newcomers. There are not the simple UI affordances avaiable in an app. Still, when working with a computer it is useful to have access to the raw power it offers.

In Linux, tools are intended to be modular components, each of which does one thing extremely well. These components are then chained together to perform more complex commands. While they may seem like a bizarre and clunky way of using an operating system, they are extremely powerful. In exchange for a small learning curve, you can automate a machine in ways that are completely impossible with graphical operating systems.

Commands are short to avoid excessive typing.

Commands

Basic Commands

See where you are (aka. the current working directory)

pwd

Stands for “print working directory.”

Show the contents of a folder (aka directory)

To show the contents of the current working directory:

ls

To see the contents of a different directory:

ls

Short for “list”.

More details:

ls -haltr /path/to/directory/

These options mean: * -h: Human readable (use Knstead of printing all sizes in bytes) * -a: Include hidden files * -l: Long format * -t: Sort by most recent time modified * -r: Reverse. Puts the most recently edited on the bottom, by the cursor.

More options can be found by reading the documentation:

man ls

Moving to a new directory

cd /wherever/you/want/to/go

Short for “change directory.”

Conventions: * Folders end in a “/”, files end in their extensions. * Hidden files and folders begin with a “.” * The current directory is referred to as “.” * The directory above the current one is referred to as “..” * Your last location is referred to as “-”.

As an example, running:

cd ./../..
cd -

Will take you two directories above your current directly, then move you back to where you started.

Viewing a file:

less /path/to/file 

Exit with “q”.

Name is an joke from the early days of Unix. The first text file viewer was named “more”, and only let you look forward through a file. less added the ability to go backwards, and caled less because “less is more.”

Editing a text file:

nano /path/to/file

Name is a mnemonic for minimal text editor.

If you want more power, and are willing to learn a small number of shortcuts to go faster:

vi /path/to/file

Many systems will also include vim, which is an extended version of vi.

Named vi because it was the successor to an editor called ex. vim is “vi improved.”

If you want a fully featured pre-internet text IDE:

emacs /path/to/file

Short for “editor macros,” a reference to it’s heavy use of macros.

Seeing the last few lines of a file:

tail /path/to/file

Running:

tail -n 100 /path/to/file

Will print the last 100 lines.

Also comes with head, to see the first lines of a file.

To print an entire file to the screen:

cat /path/to/file

Short for “concatenate,” because full purpose of this utility is to join files together by printing them out line-by-line. These streams can be joined together and made into new files.

cat fileA.txt fileB.txt > joined.txt

will concatenate fileA.txt and fileB.txt into a single file called joined.txt. The “>” takes the output of one command and writes it somewhere else, in this case a file. It might not sound like it if you are new to using the command line, but this is useful.

Clear the screen if there’s too much text:

clear

To search for text in a file:

grep "your search term" /path/to/file

grep supports an enormous number of options. A few helpful ones: * -A x and -B x: Show x lines above or below the found match * -i: ignore case * -v: Exclude lines with this match instead of including

As an example, to check for Jingle errors in the Prosody logs:

cat /var/log/prosody/prosody.log | grep -i "jingle"

The name comes from the command “g/re/p” in the (extremely old) ed editor, itself short for “general/regular expression/print.” ed is still available but is no longer in active use. Its interface was designed for pre-monitor computers printing text on a piece of paper.

Make a copy of a file

cp /path/to/source/file /path/to/location/to/copy/to/new_filename

So for example, to backup your Prosody config to a file named BACKUP.prosody.cfg.lua:

cp /etc/prosody/prosody.cfg.lua /etc/prosody/BACKUP.prosody.cfg.lua

This command is different from moving a directory, which is mv, and has the same syntax.

To look for a file or folder

Running:

find /folder/to/search/under

will give you a complete listing of all files inside that folder. Your search can be narrowed down further using grep.

Find also supports executing a command on all matching files it finds, using the -exec flag

Install software:

apt install name_of_package_to_install

Short for “advanced package tool.” apt is the best software installation tool you will ever use. One command, software installed. It’s incredible.

Run as administrator (root)

If some piece of software requires root privileges, you will need to use sudo to run it:

sudo apt install name_of_package_to_install

The name is short for “superuser do.”

View the manual for a piece of software:

man program_name

Short for “manual.”

Examine network configuration

ifconfig

This command will list the IP addresses for the network devices attached to your machine, and some assorted statistics.

Short for “internet family configuration.”

Check your DNS records

dig yourdomain.com

The name is short for “domain information groper.”

Change firewall rules

All firewall managment is done through ufw, short for “uncomplicated firewall.”

To open port 5222 for tcp packets:

sudo ufw allow 5222/tcp

To set your host to allow all outgoing connections:

sudo ufw default allow outgoing

To set your host to deny all incoming connections:

sudo ufw default deny incoming

This package may need to be installed:

sudo apt install ufw

List running processes

ps -aux

Short for “process status.”

To check if a machine is reachable

ping domain_or_ip_address

ping -6 domain_or_ip_address will perform this check over IPv6.

Named as a pair, replies are called pongs.

Changing permissions on a file

Change owner:

chown ownername:groupname /path/to/file

Change just one file’s group:

chgrp groupname /path/to/file

Change group for every file in a folder:

chgrp -R groupname /path/to/folder/

Short for “change owner” and “change group”.

To change file permissions use the chmod command. Linux’s permissions model is well outside the scope of this glossary, run man chmod if you need the documentation.

Connect to a remote machine

ssh username@machine_name_or_ip_address

Stands for “secure shell”.

Other commands

Not yet documented.