Skip to content

Linux Online Quick Guide

Linux is an operating system, just like Windows or MacOS. Its strong suit is the cli, or command line interface. This makes Linux most commonly used on servers, and is the default choice for most supercomputing environments.

Prompt

The commands prompt is the first thing you see on a Linux system. It tells you which user you are logged in as, what server you are using, and where you are currently located in files or folders.

[user@machine folder]$ type your command here

When you first log in, you are put in what's called your home folder. On most Linux systems this is /home/you_username, but on the clusters it is /data/user/you_username. You can tell when you're in your home directory if your prompt has a ~ where it tells you which folder you're in. (This is a tilde, it references your home directory).

[user@machine ~]$

Commands

Here is a useful list of basic commands. This is certainly not a full list of everything you can do.

Command Name Description
man <command> Manual Detailed guide for how to use any command
pwd Print Working Directory Shows where you currently are located on the server. AKA "where am I?"
cd <go/to/folder> Change Directory Change which directory you are currently in
ls
ls -l
ls <directory>
List Directory Content List the files or folders in the current directory or a different one. Include "ls -l (Lowercase L ) for more details on the files
mkdir <directoryname> Make Directory Make a new folder
cp -r <copy/from> Copy Copy a directory or file(s) from one location to another. The -r means recursive, which is required when copying folder
touch <file> Create Empty file Creates an empty file with nothing in it
history Show the command history Shows all the commands you previously typed
module load <softwarename>       Load Environment Gives you access to any pre-defined set of software on the cluster.(Ex Python, R, OneDrive)
python scriptname.py Run Python Run a Python script. Make sure to run "module load python-libs" to load the software required

Terminal Tips

Extra functionalitites to be aware of when using a terminal session. Many will streamline usage.

  • Up/Down Arrow Keys: see previous/next command you typed
  • Left/Right Arrow Keys: move cursor left/right (mouse does not function in terminals)
  • Tab: auto-complete the name of files/programs, double-tap tab shows matches for non-unique cases

Paths - Absolute vs. Relative

Knowing how to navigation a Linux-based file system is crucial, especially when it comes to identifying and using absolute vs. relative paths. Paths are used in a lot of commands.

Absolute Relative
Starts with "/", which means "Beginning of server" Does not start with a "/", which means "starting where I currently am".
Examples:
/data/groups
/data/users/username/my_dir
/data/users/username/my_file.py

Absolute is exact and specific, which means it doesn't matter where you are when you run it. It always refers to the same file or directory.

our can use "pwd" to get the absolute path of your current directory.





See those periods?


You can do "../../../" to go up 3 times

Symbolic links (or 'symlinks') are directories which look normal, but actually forward to another destination on the system. For example, a directory ~/research could actually forward data to /data/groups/my_research_group/my_project. So whenever you copy files into ~/research, it would store those changes in /data/groups/my_research_group/my_project.

To create a symlink you can use ln

ln -s /path/to/file /path/to/symlink

Tutorials

All computers are organized into filesystems. The filesystem is how data is stored on the disk. When you load into a prompt, you are 'in' a directory.

First, look around at what's in your filesystem with ls (list). This lists all of the files in the directory you are currently in. Directories (folders are highlighted in blue, and different types of files are highlighted as various other colors)

Now, create a new directory with mkdir my_directory. Now if you ls again, you'll see my_directory in the list. You can list all of the files in my_directory with ls my_directory. Because we just created this directory, there's nothing in it, so there won't be anything printed.

Run cd my_directory. This changes our directory so that any changes we make happen inside our folder my_directory. When you look at your prompt, you should see

[your_username@bose my_directory]$ 

You can see that now our prompt says my_directory instead of ~ (our home directory).

Let's create a file with nano myfile.txt. This will open a text editor nano. Inside this tool you can write whatever you want to the file, then hit ctrl+x to exit, y to say yes to saving changes, and enter to save the file as that filename.

Now when we ls we should see myfile.txt listed. Now that we made a file, let's print its contents.

We can print everything inside our file with cat myfile.txt.

You can manipulate the things printed from a file with tools such as tail, head, grep, and sort. These tools aren't covered in this guide, but are very useful tools.

Now that we've written and read a file, let's delete it. We can run rm myfile.txt to ReMove our file. Now when we ls our file doesn't show up. Note that when you delete a file with rm, it's gone forever, so be very careful with what you delete.

Let's cd .. to change directories to the directory above the one that we're in. If we ls we should see my_directory in our list. Now we can run rm -r my_directory to delete it. When deleting a directory, you need to specify -r (recursive) to tell rm to delete directories.

Warning

When you delete a file or directory on the cluster, its gone. There are no backups of files on the cluster, and there are no ways to recover a file once its deleted with rm or a similar command.

Extra Help