Linux command guide

June 15, 2013

The following is a short list of the most common or useful commands you can find on Harvard’s instructional UNIX environment and on most modern Linux distributions.

Command Function
ls list names of files and directories (see: directory)
date print the date
cal print a calendar
cp copy a file or directory1
mv move a file or directory1
rm remove a file1 (see: removal)
cat output the contents of a file or concatenate many files
rmdir remove an empty directory1
mkdir make a new empty directory
pwd print the path of the current working directory (see: working directory)
cd change working directory (see: working directory)
exit exit the shell (see: shell)
nano edit text files with a simple interface (see: text file)
vim edit text files with speed and efficiency (see: text file)
emacs edit text files and give yourself various wrist strain injuries (see: text file)
ssh securely obtain shell access to a remote computer
less read a text file (see: pager)
more read a text file (see: pager)
diff display any differences between two files
who show who else is logged in
man get help and information from the manual pages

Relative file paths

In Linux, it is useful to visualize a file system like the underground roots of a tree: the stump is the topmost directory, known simply as /. A directory in the topmost directory, alpha, would be known as /alpha. A beta directory inside alpha would be known as /alpha/beta. Because we are showing the entire root structure from stump to tiny roots, these paths are known as absolute.

Relative paths are paths specified with respect to your current working directory. Let’s say I’m in a directory called s111, whose absolute path is /home/alexander/harvard/s111. When constructing a relative file path, you use the keywords . and .. (one period and two periods) to refer to the current directory and the parent directory, respectively. So, if my current working directory is /home/alexander/harvard/s111, the relative path ../ refers to the directory known by the absolute path /home/alexander/harvard. Further, the relative path ../../ goes up two directories. I can even use this method to specify another file or directory in my home folder (/home/alexander), perhaps my todo list: ../../todo. In a shell, these keywords . and .. can be used instead of specifying an absolute path, wherever necessary.


directory. Analogous to a “folder” in a graphical user environment like Windows or Mac OS X. Contains files and other directories.

pager. A program that divides a text file into pages and allows the user to read the file one page at a time. Each page is as large as the terminal window.

relative file path. Specifying the way to reach a file relative to your current working directory (e.g., the relative path ../test.txt) refers to a file test.txt in the directory containing the current working directory).

removal. Analogous to deleting a file in a graphical user environment like Windows or Mac OS X, but not alike to moving a file to the Recycle Bin or Trash. Removing a file destroys it, with little hope of recovery. Be careful!

shell. A program that gives you the ability to run other programs and see the output of those programs. The characters that appear each time the shell is waiting for your input is called the prompt.

text file. Also called a plain text file. These often have the simple file extension .txt. Such files contain just characters; no ability to adjust formatting (like fonts or color). Text files are used to write source code for programming (like Java or C programs).

working directory. The directory the shell considers the “current” one; in other words, when specifying a relative file path, the shell “starts” in the working directory.

  1. These commands will not stop and prompt you before overwriting or completely eradicating a file! Be careful.  2 3 4