Skip to content

Linux Basics

Many HPC clusters, including our system, run on Linux. This page will cover basic Linux commands and concepts to help you navigate and perform essential tasks on the cluster.

What is Linux?

Linux is an open-source operating system widely used in scientific computing and HPC environments. It provides a powerful command-line interface (CLI) where users can execute commands to interact with files, manage jobs, and run software.


Basic Linux Commands

The Linux file system is hierarchical, with directories (folders) and files organized in a tree-like structure. Here is an picture for a general overview. There is also further information on filesystems at the linux foundation.

Some basic navigation commands are:

pwd (Print Working Directory): Shows your current directory.

$ pwd

ls (List): Lists files and directories in the current directory.

$ ls

Add flags for more details:

$ ls -l    # Shows detailed information about files
$ ls -a    # Includes hidden files

Notice when doing ls -a, there are two special directories. A directory called dot (.) and a directory called dotdot (..). The dot is your current directory, and the dotdot is the parent. These will come in very handy later.

cd (Change Directory): Moves you to a different directory.

$ cd /path/to/directory

To go back to the home directory, simply type:

$ cd

Note that your home directory in any UNIX/Linux is also called ~, and from anywhere on the filesystem you can reference it as such. This comes in very handy. Therefore, this will also take you back home:

$ cd ~

Similarly, if you are in some other directory, and wanted to say edit a file in your home directory called foo.txt with vim, you would do:

$ vim ~/foo.txt

To move up one directory level, use:

$ cd ..

File Operations

Here are some basic file operations you'll need to perform.

cp (Copy): Copies files or directories.

$ cp file1.txt /path/to/destination/

Use the -r option to copy directories recursively:

$ cp -r /path/to/directory /path/to/destination/

mv (Move): Moves or renames files and directories.

To move a file:

$ mv file1.txt /path/to/destination/

To rename a file:

$ mv oldname.txt newname.txt

rm (Remove): Deletes files or directories.

To delete a file:

$ rm file1.txt

To delete a directory and its contents, use the -r flag:

$ rm -r /path/to/directory/

Caution: rm permanently deletes files, so be careful when using it.

Viewing File Contents

Linux provides several commands to view the contents of files:

cat: Concatenates and displays the contents of a file.

$ cat file1.txt

less: Allows you to scroll through a file one screen at a time.

$ less file1.txt

Use spacebar for next page and up/down arrows or pageup/pagedown to move in the less pager. Hit the "q" key to quit.

head and tail: View the first or last few lines of a file.

$ head file1.txt  # Shows the first 10 lines
$ tail file1.txt  # Shows the last 10 lines

To display more lines, use the -n option:

$ head -n 20 file1.txt

Text Editors

Linux offers several text editors you can use to create and edit files.

nano: A simple command-line text editor. Conceptually nano behaves like a very plain text editor, controlled with arrow keys.

To open a file with nano:

$ nano file1.txt

Basic shortcuts: - CTRL + O: Save changes. - CTRL + X: Exit.

vim: A powerful text editor that may be installed on the cluster. Conceptually vim has two modes, insert and normal. In insert mode, it kind-of behaves like a plain editor, and in normal mode it is a powerful tool full of shortcuts. You will do "plain editing" in insert mode, and powerful editing can be done in normal mode.

To open a file with vim:

$ vim file1.txt

Basic vim commands: - Press i to enter insert mode. - Press ESC to exit insert mode. - Type :x to save and exit. - Type :w to save (write changes) without exiting. - Type :q! to exit without saving. - Arrow keys work for navigation, but see Vim Help for powerful movements.

Managing Permissions

Every file and directory in Linux has associated permissions that determine who can read, write, or execute them.

ls -l: Displays detailed information, including permissions, for each file and directory.

$ ls -l

The output looks like this:

-rw-r--r-- 1 user group  4096 Jan  1 10:00 file1.txt

The first part (-rw-r--r--) shows the file permissions:

  • r: Read permission
  • w: Write permission
  • x: Execute permission

The grouping of the first part is User, Group, Others, meaning in our previous example, the User has Read and Write permissions, the (-rw-) part, and the Group and Others on the system have read permissions, the (r--r--) part.

chmod (Change Mode): Modifies file or directory permissions.

To give everyone read and execute permissions on a file:

$ chmod 755 file1.txt

Common permission settings:

  • 755: Read, write, execute for the User; read and execute for Group, Others. (-rwxr-xr-x)
  • 644: Read, write for the User; read-only for Group, Others. (-rw-r--r--)

Getting Help in Linux

If you need more information on any Linux command, you can use the man (manual) command:

$ man command_name

For example, to learn more about the ls command:

$ man ls

This will bring up the manual page for ls, explaining all the available options.

Further Resources

With these basic commands, you’ll be able to navigate and work within the Linux environment on the HPC cluster. Don't hesitate to refer back to this page or reach out for help if needed.


Up Next

Loading Software