using Linux


Navigation

What is Linux?

Linux is an open source (free!) operating system capable of performing most of the same tasks as a Windows or Mac computer. It can be accessed using a GUI (windowed) environment or through the command line. This page focuses on the command line aspect of Linux, largely because the command line is the starting point for remote access.


Accessing Linux

If you're using a non-Linux machine and you want to connect to one running Linux, you need to use a program that provides Secure Shell (SSH) connections. This enables a secure path for your computer to "talk" to the Linux one. In this program, you'll enter your username and password for the Linux computer and--depending on the program--enable other settings as well.

Windows

There are numerous Windows SSH software options, but this guide will focus on PuTTY. (To install PuTTY, simply download putty.exe from the PuTTY webpage.) PuTTY is a customizable open source program which allows you to save connection information rather than entering it every time you connect. This is particularly useful when you have accounts on more than one Linux machine. This is a screenshot of the window that opens when you start PuTTY:

Screenshot showing settings for a PuTTY terminal
Enter the hostname (a domain name or an IP address) of the computer you intend to access. Use port 22 unless instructed otherwise by the system administrator. At this point you can connect... but you won't be able to display any content from the computer. So if you intend to use GrADS or NCL or Python or any other software that may produce a window when they run, those programs will fail.

Follow a two-step process to remedy this. First, enable X11 forwarding in PuTTY:

Screenshot showing how to open the SSH settings in the PuTTY configuration menu
To avoid doing this each time you log in, return to "Session" (at the top of the left hand menu; you may need to scroll up), give your connection a name in the "Saved Sessions" box, and then hit "Save."

Second, install Xming. Xming is a X window system server that enables your computer to accept incoming display information. Note that Xming needs to be running before you start your PuTTY SSH session.

To begin your SSH session, enter your login information and then hit "Open." If you have saved your login information, click the saved session, hit "Load," and then hit "Open."

Mac OS X

Mac OS X has one built-in program that allows you to connect to a Linux machine: the Terminal app. HOWEVER, if you want to run something that produces graphics like GrADS or matplotlib in Python, you need the X11 terminal (shown below).

Screenshot showing a basic X11 terminal in Mac OS X
Obtain the X11 terminal app by installing XQuartz. To log in via the X11 terminal, type the following command:

        $ ssh -Y username@domainname     (do NOT include the $ sign)     SSH manual page


commonly used Linux commands

The $ sign indicates a terminal command and should not be included when you type it. Many of these commands can be modified through the use of options. Click on the link next to each command for more information and examples.

$ ls     list files

$ cd [dirname]     change directory

$ mkdir [dirname]     create directory

$ pwd     print current directory

$ cp [file] [file2]     copy a file

$ mv [file] [file2]     move a file (and/or rename a file)

$ rm [file]     delete a file (USE WITH CARE)

$ rmdir [directory]     delete a file (delete empty directory)

$ more [file]     print contents of file (must be plain text)

$ head [file]     print first 10 lines of file

$ tail [file]     print last 10 lines of file

$ top     display currently running processes (akin to Task Manager on Windows or Activity Monitor on Mac OS X)

$ free     display amount of free/used memory (RAM, not hard drive space)

$ wget     download files from HTTP or FTP web addresses

$ tar     extract archive (.tar, .tar.gz, .tgz) files

$ date     print current date and time information or change computer date/time

$ cat     display contents of a file or concatenate (join) two or more files

$ cmp [file1] [file2]     compare contents of two files

$ man [command]     display manual page for a given command (e.g., ls,tar,wget)

$ which [command]     locate path of given command

$ df     display free disk space

$ du     display disk usage of given file/directory

$ passwd     change your login password

more advanced commands

$ grep     search for pattern in files

$ find     search for files

$ sed     stream editor (best used with regular expressions)

$ rename     rename utility (useful when trying to remove or replace spaces, underscores, etc. in a number of file names)

$ rsync     copy files and check for consistency between folders, hard drives, or even computers (can also be used as a backup utility)



Another resource: Linux commands from the guide on Wikibooks


(page last updated February 2022)