Linux — Permissions, Pipes & the Environment¶
This article picks up where Linux Basics left off. You should already be comfortable navigating the filesystem and managing files. Here you'll learn how Linux controls access to files, how to chain commands together with pipes, and how to configure your shell environment.
Interactive first
Try the hands-on terminal tour below before reading the reference sections. You'll practice permissions, pipes, redirection, and modules in a guided simulation without needing real cluster access.
The Terminal Tour¶
You've already set up your workspace from the basic tour. Now it's time to go deeper: control who can access your files, chain commands together, and manage software modules.
Enter your NetID below, then click SSH into Discovery → to begin.
File Permissions¶
Every file on Linux has a set of permissions that control who can read, write, or execute it. When you run ls -l, the leftmost column shows them:
-rw-r--r-- 1 f00abc f00abc 312 Mar 10 14:22 README.txt
drwxr-xr-x 2 f00abc f00abc 4096 Mar 10 14:22 my_project/
The permission string has 10 characters:
- rw- r-- r--
│ │ │ └── others: read only
│ │ └────── group: read only
│ └────────── owner: read + write
└──────────── file type (- = file, d = directory)
Each group of three characters is rwx: read, write, execute.
Why this matters on HPC¶
On a shared cluster, files in your home directory are typically readable only by you. Files in a shared lab volume may be readable by your whole group. Scripts you want to run must be executable:
chmod +x run_analysis.sh # make a script executable
chmod 750 my_project/ # owner: rwx, group: r-x, others: ---
Check before you share
Before copying sensitive data to a lab volume, check the permissions on that volume with ls -la. By default, new files inherit the permissions of their parent directory.
Pipes and Redirection¶
One of Linux's most powerful ideas: the output of one command can become the input of another.
The pipe |¶
cat results.csv | grep "PASS" | wc -l # count passing variants
ls -l | sort -k5 -rn | head # 10 largest files
Redirect output to a file >¶
grep "PASS" results.csv > passing_variants.csv # overwrite
grep "FAIL" results.csv >> all_variants.csv # append
Redirect input from a file <¶
Discard output¶
Environment and Dotfiles¶
Environment variables¶
Your shell has environment variables — named values that affect how programs run. The most important one is $PATH, which tells the shell where to look for commands:
Dotfiles¶
Files starting with . are hidden from plain ls. Your home directory contains several of these dotfiles — configuration files that are loaded every time you open a shell:
| File | Purpose |
|---|---|
~/.bashrc | Runs every time you open a new shell. Put aliases, module loads, and $PATH additions here. |
~/.bash_profile | Runs at login. Often just sources ~/.bashrc. |
~/.profile | Login config for non-bash shells. |
To apply changes after editing ~/.bashrc without logging out:
Environment modules on Discovery¶
Now that you know about $PATH, here's the practical payoff: Discovery uses an environment modules system so you never have to edit $PATH by hand. When you load a module, the system updates your environment variables automatically:
That's all you need for now. Modules are central to working on the cluster: Loading software, managing versions, and keeping your jobs reproducible are all important concerns in HPC land, so they have their own dedicated article.
Quick Reference¶
| Category | Command | What it does |
|---|---|---|
| Permissions | ls -l | Show permissions |
chmod +x file | Make file executable | |
chmod 750 dir/ | Set numeric permissions | |
| Pipes | cmd1 \| cmd2 | Pipe output to next command |
| Redirection | cmd > file | Write output to file (overwrite) |
cmd >> file | Append output to file | |
cmd < file | Read input from file | |
cmd > /dev/null 2>&1 | Discard all output | |
| Environment | echo $VAR | Print variable |
source ~/.bashrc | Reload shell config | |
| Modules | module avail | List available software |
module load name | Load software module | |
module list | List loaded modules | |
module purge | Unload everything |
What's Next¶
- Storage on Discovery: Understand your home directory, lab volumes, and scratch space
- Submitting your first job: Put the scheduler to work with
sbatch - All about modules: Setting the stage by loading the right software for the job