Lab 03 — Shell environment foundations
Goal
Configure your ~/.bashrc on Unity for productive, collaborative HPC work — install aliases that save typing, add umask 002 so files you create can be read by your group, and develop a clear understanding of which Unix groups and Slurm partitions you actually belong to.
By the end of this lab, typing getnode should request an interactive compute node, runs should show your Slurm queue, and proj should drop you into your lab project directory.
Reading
- Handbook: Shell Environment — sections 1–4 in detail (startup files, aliases, groups/partitions). Skim section 6 (
umask); you’ll come back to it during the lab.
Budget ~25 minutes for the reading.
Learning objectives
- Explain the difference between
.bash_profileand.bashrc, and verify yours are chained correctly. - Find your own Unix groups (
groups,id,getent group) and Slurm partitions (sacctmgr show association). - Install
umask 002and explain when it matters (and when it’s overkill). - Add 5+ aliases tailored to your real workflow, plus at least one shell function.
- Reload
.bashrcsafely without breaking your shell.
Setup / prerequisites
- Lab 01 complete —
ssh unityworks. - Lab 02 complete — VS Code Remote-SSH is connected; you have an integrated terminal on Unity.
- An OSU/ASC account that has been added to at least one Unix group beyond just yourself (most students are, automatically — verify in Task 2).
Work entirely in VS Code’s integrated terminal on Unity, not a local terminal — that way you can edit ~/.bashrc in VS Code and re-source it in the terminal next door.
Tasks
1. Inspect your existing startup files (5 min)
cat ~/.bash_profile
cat ~/.bashrcOn Unity, your ~/.bash_profile should contain something like:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi✅ Self-check: that block exists. If it doesn’t (rare on Unity, common on macOS), add it now — see Handbook §2.
2. Discover your Unix groups (5 min)
groups
# Example output: yourname.## somelab
id
# Example output: uid=12345(yourname.##) gid=12345(yourname.##) groups=12345(yourname.##),5678(somelab)If you have access to a shared lab directory, see who else is in your group:
getent group somelab
# Example: somelab:x:5678:alice.1,bob.123,yourname.##Save the output of groups and id — they’re part of your deliverables.
3. Discover your Slurm partitions (5 min)
sacctmgr show association user=$USER format=Account,Partition
sinfo -o "%P %a %D"The first command shows which partitions you’re authorized to submit to. The second shows every partition that exists on the cluster.
For most students, you’ll have at least the batch partition (the free public one). If you also have a lab partition, you’ll see that listed.
✅ Self-check: you can name at least one partition you can submit to. (For Labs 8 onwards, you’ll specify this as #SBATCH --partition=....)
4. Add umask 002 to your .bashrc (10 min)
If you’re working in a shared lab directory under /fs/project/<group>/, umask 002 ensures files you create are group-readable and group-writable by default. Without it, your labmates have to chase down chmod-permission errors on every file you create.
In VS Code, open ~/.bashrc:
# From the integrated terminal:
code ~/.bashrcAdd this line near the top (anywhere works, but near the top is conventional):
# Default permissions: group can read+write files I create.
# Critical for shared lab directories on Unity.
umask 002Save the file. Then in the terminal:
source ~/.bashrc
umask # confirm output is 0002✅ Self-check: umask prints 0002.
5. Install useful aliases (15 min)
Add at least 5 aliases to your .bashrc. Pick ones that fit your real workflow. Here’s a sensible starter set — adapt the paths and partition names to your actual values (e.g. replace <group> with batch or your lab partition name):
# ─── Slurm shortcuts ─────────────────────────────────────────
# Quick interactive compute node
alias getnode='sinteractive -p <group> --cpus-per-task=4 --mem=16G --time=04:00:00'
# See your queue without typing your username every time
alias runs='squeue -u $USER'
# ─── Filesystem shortcuts ────────────────────────────────────
# Long listing sorted by modification time
alias lst='ls -lhtr'
# Print the absolute, canonical path of the current directory.
# Useful because plain `pwd` can return symlinked paths that look right
# but cause trouble when fed to scripts.
alias rpwd='realpath .'
# ─── Project jumps ───────────────────────────────────────────
# Jump to your lab's project directory (replace path with yours)
alias proj='cd /fs/project/<group>/<username>/'Save and source:
source ~/.bashrcTest each alias:
runs # should show your queue (likely empty)
lst # should show files sorted by date
rpwd # should print an absolute path✅ Self-check: each alias runs cleanly in a fresh VS Code terminal tab (open one to verify .bashrc is sourced automatically).
6. Add a shell function (10 min)
Aliases can’t take arguments — for that, use functions. Add this to ~/.bashrc:
# Show the working directory of one of your Slurm jobs.
# Find a job ID with `runs` first, then:
# slinfo 5067189
slinfo() {
scontrol show jobid -dd "$1" | grep 'WorkDir' | sed 's/WorkDir=//' | sed 's/[[:blank:]]//'
}Source and test (once you have a real Slurm job ID — for now, just verify the function is defined):
source ~/.bashrc
type slinfo # should print "slinfo is a function"
declare -f slinfo # should print the function bodyYou’ll get to use slinfo for real in Lab 08.
7. Verify everything survives a new shell (5 min)
Open a fresh VS Code integrated terminal (the + button in the terminal panel). Run:
umask # should be 0002
runs # should run (your alias works)
type proj # should show the alias definition
type slinfo # should show "slinfo is a function"If anything is missing, your .bashrc wasn’t sourced — most likely your .bash_profile isn’t chaining to it (back to Task 1).
Deliverables
Save the following to lab03/ in your personal course-deliverables repo:
lab03/bashrc_additions.txt— paste just the lines you added to~/.bashrc(umask, aliases, slinfo). Redact<group>,<username>, and any real paths.lab03/groups_partitions.txt— the output of:echo "=== groups ===" ; groups echo "=== id ===" ; id echo "=== partitions ===" ; sacctmgr show association user=$USER format=Account,Partitionlab03/reflection.md— 5–7 sentences answering:- What’s the difference between an alias and a function, and why do you need both?
- What does
umask 002actually do (in terms of file permission bits), and why is it good for shared lab directories? - What partition will you use as the default
<group>value in later labs?
Self-check
Common issues
❌ I added an alias and it doesn’t work
You need to re-source .bashrc or open a fresh shell. Editing the file doesn’t affect running shells. Run source ~/.bashrc or just open a new terminal.
❌ Permission denied opening ~/.bashrc for write
Check permissions: ls -l ~/.bashrc. It should be -rw------- or -rw-r--r--. If it’s something weird, chmod 600 ~/.bashrc and try again.
❌ getnode says “Invalid partition specified”
You used <group> literally. Replace it with batch (or your actual lab partition name from Task 3).
❌ umask 002 is set but files are still created as 644
Likely causes: - You’re in a directory whose group ownership doesn’t include g+s (the setgid bit), so new files inherit your primary group instead of the directory’s group. This is more of an issue for directories than for the umask itself. - A later line in .bashrc is overriding it (umask 022). Check by running grep umask ~/.bashrc.
❌ slinfo isn’t recognized when called from a script
Functions defined in .bashrc are only available in interactive shells, not in scripts started with #!/bin/bash. Use export -f slinfo after the function definition, or just call the underlying scontrol directly in scripts.
Time estimate
- Reading: ~25 min
- Tasks: ~50 min
- Deliverables: ~10 min
Total: ~1.5 hours
Extensions (optional)
Set up a ~/.secrets file for API keys
If you have an Anthropic API key, OpenAI token, AWS credentials, etc. that you don’t want sitting visible in .bashrc:
# In ~/.bashrc, at the end:
[ -f ~/.secrets ] && source ~/.secrets
# In ~/.secrets:
chmod 600 ~/.secrets
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.secretsNow .bashrc can be committed somewhere (it doesn’t contain secrets), and .secrets stays out of git.
Customize your prompt
Add a PS1 line to .bashrc that includes your current conda env and the cluster name:
export PS1='\[\e[1;31m\]\h\[\e[0m\]:\w \$ '(Many shell prompt customization frameworks like Starship work on Unity too.)
What’s next?
With a solid shell setup, Lab 04 — Persistent sessions: tmux + livenode turns to making your sessions survive disconnects.