Linux Basics

This page provides a basic introduction to using Linux, specifically geared toward the Linux systems at Thayer School.

Logging In

In order to log into any of our Linux systems, you will need to use your NetID and your Dartmouth password. See NetID Username and Managing Passwords for details about these credentials.

The Linux File System

The Linux file system is a hierarchical filesystem that begins with the "root" directory - '/' All other directories descend from this. On all of our Linux systems, the ThayerFS shares are mounted under the /thayerfs directory and jumbo shares under the /jumbo directory. Although this appears and behaves as a local directory, it is in fact remote. Here is a partial example of the directory structure on our systems:

|-- bin
|-- dev
|-- etc
|-- lib
|-- sbin
|-- jumbo
|   `-- bigdata
|-- thayerfs
|   |-- common
|   |-- courses
|   |-- home
|   |   `-- d12345q
|   `-- research
|-- tmp
|-- usr
|   `-- local
|       `-- bin
`-- var
    `-- log

The Shell

If you are at the console of one of Linux systems (for example in Cummings 218), you can use the graphical user interface to do much of what you need to do with the system. However, if you are using systems remotely or as you need to access advanced functionality, you will need to begin using the shell - also referred to as the command line. This is analogous to the command prompt in Windows.

If you use ssh to connect to one of our systems remotely, you will already be at a shell prompt. If you are at the console of a Linux Lab system, you can either right-click on the desktop and select "Open Terminal," or select the Terminal application from the Applications->Thayer pull-down menu.

As you will find with linux, there are many ways to do almost everything - the shell is no exception. On our systems, the default shell is called bash (the Bourne-again shell, named after one of the original authors). The are other shells that can be used which have slightly different characteristics - everything on this page will be specific to the bash shell.

Shell Prompt

When the shell opens, you will get a message about your home quota usage and you will then see the shell prompt, which should look like:


The first part of the prompt is the machine on which the shell is running, then a colon, and then the current directory. The tilde (~) character is shorthand for your home directory - the actual directory is something like /thayerfs/home/d12345q. Finally, the shell prompt ends in a dollar sign ($) character.


One of the fundamental things to understand at the shell prompt is filesystem navigation. As you do things at the shell prompt, you will likely need to change your location, since commands that your type will act on files that exist in your current location, unless you specify otherwise. To determine your current location, you can either look at your prompt, which should have your current directory in it, or you can use the 'pwd' (print working directory) command:

vanguard:~$ pwd

To list the files in the current directory, you use the 'ls' command:

vanguard:~$ ls
Desktop  Documents  Music  Pictures  Public  Templates  Videos  web

The behavior of most Linux command can be changed by adding "switches" to the command. With the ls command, if you want to see all the file information, including dates and sizes, you can use the '-l' (lower-case L) switch:

vanguard:~$ ls -l
total 32
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Desktop
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Documents
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Music
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Pictures
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Public
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Templates
drwxr-xr-x 2 d12345q +thayerusers 4096 2009-01-07 10:08 Videos
drwx---r-x 2 d12345q +thayerusers 4096 2008-01-07 10:08 web

This listing shows the permissions (an initial 'd' indicates a directory), the file owner and group, and the modification date and time.

To change the current directory, you use the 'cd' command. For example, to change to the top-level ThayerFS research directory, you could type:

vanguard:~$ cd /thayerfs/research/

To create a new directory, you use the 'mkdir' command. This command will only work in a directory for which you have write permission (e.g. your home directory):

vanguard:~$ mkdir new_folder
vanguard:~$ cd new_folder/
vanguard:~/new_folder$ pwd

Two special directory "shortcuts" may be useful as well. The directory '.' (a single period) refers to the current directory, and the directory '..' (two periods) refers to the "parent" of the current directory. So, if you wanted to go up a level in the directory hierarchy, you could type 'cd ..':

vanguard:~$ pwd
vanguard:~$ cd ..
vanguard:/thayerfs/home$ pwd

Execution Path

When you type a command at the shell, this command must be in the execution path in order to be found. You can see your current execution path by looking at the "PATH" environment variable:

vanguard:~$ echo $PATH

A consequence of this is that your current directory is not usually in the execution path. To run a command that is not in your execution path, you need to specify the path explicitly. For commands in your current directory, you can use the directory "./" to run it. For example, if I have a program called myprog, I can run it like this:

vanguard:~$ ./myprog

Case Sensitivity

In Linux, the filesystem is case sensitive. This means that it is perfectly valid to have two files, one called 'newfile' and another called 'NewFile'. This is different from the Windows filesystem, which is simply case-preserving.

Other basic commands

Here are a few other basic commands that will be useful:

  • cat - Display the contents of a file to the screen
  • less - Display the contents of a file, one screen-full at a time
  • mv - Move or rename a file or directory
  • cp - Copy a file
  • rm - Delete a File
  • rmdir - Remove a directory

And, perhaps most importantly, is the 'man' command. This is short for manual, and provides help on nearly any command. To use this you type 'man command' where "command" is the command for which you'd like help. For example, to learn all about the ls command, you would type:

vanguard:~$ man ls

Editing Files

When working with text files, there are several options for editing the files. If you are at the console, a good general-purpose editor is gedit. This can be run by selecting Text Editor from the Applications->Accessories drop-down menu. You can also run it from the shell by simply typing gedit. You can also type an existing filename after gedit to open this file specifically"

vanguard:~$ gedit myfile.txt

There are several text-based editors that can be used from either the console or remotely. Some of the most widely-used are:

  • vim
  • emacs
  • nano

Each of these operates differently. To use any of these, you can view the man page (e.g. man vim) and/or search for information about them on the internet. Here are a couple of good pages to start with:


In order to run C or Fortran programs, they need to be compiled into binaries that the system can execute. We have many different compilers available (see the Linux Services page), but here are some very basic examples.

If you created a very simple C program in a file named hello.c:

#include <stdio.h>

    printf ("Hello World!\n");

you could compile it with this command:

$ gcc -o hello hello.c

This uses the GNU C Compiler (gcc) to compile the file hello.c into the executable file 'hello'. The file can then be run like this (remember that the working directory is likely not in your path, so you must use the './' to specify where it is):

$ ./hello 
Hello World!

Similarly, if you have a basic Fortran program in a file named hello.f:  Note, each line is indented 6 spaces.  This is an historical artifact from when the first 6 spaces were reserved for line numbers.  If you name your file with a .f95 extension, gfortran will compile without requiring line indents.

      program hello
         print *,"Hello World!"
      end program hello

you could compile it with the GNU Fortran 95 compiler:

$ gfortran -o hello hello.f

If you use external libraries in your program, for example curl_encode.c:

#include <stdio.h>
#include <curl/curl.h>

    CURL *curl = curl_easy_init();
    if(curl) {
        char *output = curl_easy_escape(curl, "data to convert", 15);
        if(output) {
            printf("Encoded: %s\n", output);

trying to compile will result in an error:

$ gcc -o curl_encode curl_encode.c
/tmp/ccNeOnuH.o: In function `main':
curl_encode.c:(.text+0x99): undefined reference to `curl_easy_init'
curl_encode.c:(.text+0xba): undefined reference to `curl_easy_escape'
curl_encode.c:(.text+0xe7): undefined reference to `curl_free'
collect2: error: ld returned 1 exit status

In order to compile this, you need to "link" the executable program to the curl (libcurl) library, which contains the actual compiled code for the curl functions:

$ gcc -o curl_encode curl_encode.c -lcurl
$ ./curl_encode
Encoded: data%20to%20convert

Further Reading

Here are some other external sites that have more basic Linux information:

Still need help? Contact Us Contact Us