The command line (terminal) is a “manual” text-based user interface that you can use to communicate with your computer without a graphical interface. The terminal has several ways of interpreting your commands through Unix shells (command languages). A command is interpreted as input any time you press ENTER.
First and foremost: it is important to understand how files are organized on a Unix system. The server runs on the Linux Ubuntu operating system (OS), which is based on Unix. Unix is incredibly versatile, with multi-user and multi-tasking capabilities. It also has a very intuitive hierarchical filesystem (see the diagram below).
Files are grouped into folders, which are called directories in Unix. The root directory ( / ) houses the top level of the filesystem. Further information here.
The standard bin subdirectory ( /bin ) contains executable programs that must be available in order to attain minimal functionality for the purposes of booting and repairing a system. You probably won’t need to access this directory for your purposes. Further information here.
The other directories in the root directory are not important for now, except for the home directory. All users on a Linux system have a home directory ( /home/mthomas is the home directory for the user mthomas in the diagram above). When you connect to the server, your default working directory is your own home directory, also denoted by ~/ (check by typing pwd when you log in, or look for a tilde ‘~’ next to your command prompt).
Your home directory has two standard subdirectories, bin ( /home/mthomas/bin = ~/bin ) and .profile ( /home/mthomas/.profile = ~/.profile ). These directories store your user’s environment variables and binaries (machine code). You probably won’t need to access these either. Note that directories beginning with a period are hidden. Further information about the home directory here.
Finally, you can create new directories in your home directory, such as class_stuff in the diagram above. These directories can store your files or other subdirectories you create.
Here are a few How-To pages on the basics of Linux, created by the Linux Information Project:
Here is the index of all How-To pages by the Linux Information Project.
You should also take a look at this guide made specifically for Linux Ubuntu before attempting any of the instructions below.
Command | What it stands for | What it does / usage |
---|---|---|
pwd | “print working directory” | Tells you your current location in the filesystem |
cd | “change directory” | Navigates to another directory; |
cd /home/user/raw_data/ sets your working directory to the raw_data directory in your home directory | ||
ls | “list” | Prints a list of all files and directories in your current working directory; ls -al prints a more detailed list of these items, including user privileges, file size, date created |
man | “manual” | Read about the functions of the following command; man man displays the manual of the manual, man cd displays the manual of the cd command, man ls displays the manual of the ls command, etc. Press the ‘q’ key to exit |
mkdir | “make directory” | Creates a new directory with the name you provide; mkdir ~/analysis creates a directory called analysis in your home directory |
rm | “remove” | Deletes the following file; |
rm ~/analysis/job_1.txt deletes the .txt file indicated; | ||
rm -r ~/analysis recursively ( -r flag ) deletes the entire analysis directory, along with its contents; | ||
USE CAUTION WHEN DELETING | ||
cp | “copy” | Makes a copy of the indicated file; |
cp ~/analysis/job_1.txt ~/analysis/job_2.txt creates a copy of job_1.txt and names it job_2.txt in the same directory | ||
sudo | “superuser do” | Invoke superuser privileges for the following command (for commands that require them); |
sudo rm /some_directory/some_file.txt deletes the indicated file with superuser privileges; CAUTION | ||
top | “table of processes” | Displays all processes; press the ‘q’ key to exit |
mv | “move” | Moves a file to another directory; |
mv ~/analysis/job_1.txt ~/projects/job_2.txt moves the job_1.txt file from the analysis directory to the projects directory and renames it job_2.txt | ||
less | literal | Displays the contents of a file or a command output, one page at a time; |
less my_file.txt displays the first page of the file | ||
history | literal | Displays your bash command history |