Skip to content

Part 1: Linux Basics

In this section you’ll get acquainted with the Linux command line—the most powerful interface for your HPC workflows. We’ll cover command structure, essential file-management tools, handy extras, and finish up with practical exercises.


1.1 Structure of a Linux Command

Every Linux command follows this general pattern:

command [options] [arguments]
  • command: the program or tool name (e.g. ls, cp, grep).
  • options: modify the behavior of the command (e.g. -l, -r, -a).
  • arguments: file paths, directory names, or other inputs.

1.2 Navigating & Managing Files

1.2.1 Listing Directory Contents (ls)

One of the first tasks you will often perform on a Linux system is viewing the contents of a directory. This is accomplished using the ls command, short for "list."

The basic usage is:

ls

This command will show all files and directories in your current working directory. However, ls becomes even more powerful when combined with options (also called flags) that modify its behavior.

Useful Options

  • -l (long listing):

    Displays detailed information about each file or directory, including permissions, number of links, owner, group, file size, and the last modified date.

    Example
    ls -l
    
    Output
    -rw-r--r-- 1 username group  4096 Apr 27 12:00 file.txt
    drwxr-xr-x 2 username group  4096 Apr 27 11:30 documents/
    
  • -a (all):
    Lists all entries, including hidden files and directories. In Linux, filenames beginning with a dot (.) are hidden by default.

    Example
    ls -a
    
    Output
    -rw-r--r-- 1 username group  4096 Apr 27 12:00 file.txt
    drwxr-xr-x 2 username group  4096 Apr 27 11:30 documents/
    drwxr-xr-x  3 username group 4.0K Apr 26 14:22 .bashrc
    drwxr-xr-x  3 username group 4.0K Apr 26 14:22 .profile
    

    Hidden files like .bashrc and .profile will now appear.

  • -h (human-readable):
    Prints file sizes in K, M, or G rather than raw bytes, e.g. 4.0K instead of 4096.

    Example
    ls -lh
    
    Output
    -rw-r--r-- 1 username group  4.0K Apr 27 12:00 file.txt
    

Combining options

You can combine multiple options together without needing separate dashes:

Example
ls -lah

This command will list all files (-a) in long format (-l) with human-readable sizes (-h).

Output
drwxr-xr-x  4 username group 4.0K Apr 27 10:15 .
drwxr-x--- 10 username group 4.0K Apr 20 09:00 ..
-rw-r--r--  1 username group  512 Apr 27 10:15 README.md
drwxr-xr-x  3 username group 4.0K Apr 26 14:22 .config
-rwxr-xr-x  1 username group 2.1K Apr 26 16:05 run_analysis.sh

Here you can immediately see:

  • Which files are hidden (.config)
  • Who owns each file
  • When each file was last changed
  • Which scripts are executable (-rwxr-xr-x)

Exercises

Exercise 1 - List all your files

Question

List all contents of your home directory in detailed format.

Answer
[username@controller1 ~]$ ls -l /home/P123456/
-rw-r--r--  1 username group  512 Apr 27 10:15 README.md
-rwxr-xr-x  1 username group 4096 Apr 26 16:05 run_analysis.sh
[username@controller1 ~]$
Exercise 2 - List all files

Question

List all files, including hidden ones, in the currect directory

Answer
[username@controller1 ~]$ ls -a
drwxr-xr-x  4 username group 4096 Apr 27 10:15 .
drwxr-x--- 10 username group 4096 Apr 20 09:00 ..
-rw-r--r--  1 username group  512 Apr 27 10:15 README.md
drwxr-xr-x  3 username group 4096 Apr 26 14:22 .config
-rwxr-xr-x  1 username group 2100 Apr 26 16:05 run_analysis.sh
[username@controller1 ~]$
Exercise 1 - List everything

Question

List everything in your current directory with detailed information and human-readable sizes.

Answer
[username@controller1 ~]$ ls -lah
drwxr-xr-x  4 username group 4.0K Apr 27 10:15 .
drwxr-x--- 10 username group 4.0K Apr 20 09:00 ..
-rw-r--r--  1 username group  512 Apr 27 10:15 README.md
drwxr-xr-x  3 username group 4.0K Apr 26 14:22 .config
-rwxr-xr-x  1 username group 2.1K Apr 26 16:05 run_analysis.sh
[username@controller1 ~]$

Observe the differences in the output and familiarize yourself with how these options change the displayed information.

1.2.2 Copying Files and Directories (cp)

When working on an HPC system (or any Linux machine), you’ll frequently need to make copies of files or entire directories. The cp command (“copy”) handles this task.

The basic usage is:

cp source destination
  • source can be a single file or directory (when using -r), or multiple files.
  • destination is either a directory (to copy into) or a new filename.

By default, cp copies single files. To copy directories (and everything inside them), you need to add the recursive option.

Useful Options

  • -r (recursive):

    Copy directories and their contents, including all subdirectories and files.

    cp -r project_folder/ project_folder_backup/
    

Exercises

Exercise 1 – Copy a Single File

Question

In your current directory, copy report.txt to a new file called report_backup.txt.

Answer
[username@controller1 ~]$ cp report.txt report_backup.txt
[username@controller1 ~]$
Exercise 2 – Copy a Directory Recursively

Question

Copy the entire data/ directory (including subfolders) to data_backup/.

Answer
[username@controller1 ~]$ cp -r data/ data_backup/
[username@controller1 ~]$

1.2.3 Moving and Renaming Files and Directories (mv)

The mv command is used to move files and directories to a new location or to rename them.

The basic usage is:

mv source destination
  • If destination is an existing directory, source is moved into it.
  • If destination does not exist, source is renamed.

By default, mv can move or rename both files and directories without any special options; add -i to prompt before overwriting and -v to display each action.

Useful Options

  • -i (interactive):

    Prompts you before overwriting any existing files in the destination.

  • -v (verbose):

    Prints each file or directory as it is moved/renamed.

Exercises

Exercise 1 – Move a Single File

Question

Move report_backup.txt from your current directory into the backup/ folder.

Answer
[username@controller1 ~]$ mv report_backup.txt backup/
[username@controller1 ~]$
Exercise 2 – Rename a Directory

Question

Rename the directory old_folder to new_folder.

Answer
[username@controller1 ~]$ mv old_folder new_folder
[username@controller1 ~]$

Part 2