Unix is a powerful multiuser operating system. Linux is a Unix-like system commonly used in HPC. You interact with it using a command-line interface (CLI) or shell (bash). Welcome to the beginnerβs guide to Unix and the command line interface for HPC users.
pwd
ls -lh
cd /path/to/folder
cd ..
mkdir myfolder
touch file.txt
cp file1.txt file2.txt
mv file1.txt folder/
rm file.txt
rm -r folder/
cat file.txt
less file.txt
head file.txt
tail file.txt
grep "search_term" file.txt
find . -name "*.txt"
ls -l
chmod 755 script.sh
sudo chown user:group file.txt
| Command | Description |
|---|---|
man <command> |
Show manual/help |
history |
Show previously used commands |
clear |
Clear terminal screen |
whoami |
Show current user |
unix_practice.txt filesgrep to search a keyword in a filechmodfind to locate all .txt files in your home directoryA script is a file of commands executed line by line. Example: my_script.sh
#!/bin/bash
echo "Starting job..."
cd /home/user/myproject
python analysis.py
Run it with:
bash my_script.sh
#!/bin/bash
#SBATCH --job-name=test_job
#SBATCH --output=out.txt
#SBATCH --time=00:10:00
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=2
module load python
python3 analysis.py
sbatch job.slurm # Submit job
squeue -u $USER # Check job status
scancel <jobid> # Cancel job
top # Real-time CPU usage
htop # Enhanced top (if available)
squeue -u $USER # Job queue
sacct -j <jobid> # Job accounting info
| Practice | Example |
|---|---|
| Start with a shebang | #!/bin/bash |
| Enable safe scripting | set -euo pipefail |
| Use logging | command >> log.txt 2>&1 |
| Use comments | # This part runs the model |
| Use variables | FILENAME=data.txt |
| Automate with loops | for f in *.txt; do ...; done |
| Command | Description |
|---|---|
pwd |
Show current directory |
cd dir/ |
Change directory |
ls -l |
List files |
mkdir dir |
Create folder |
rm file |
Delete file |
cp a b |
Copy a to b |
mv a b |
Rename/move a to b |
bash script.sh |
Run script |
sbatch job.slurm |
Submit job |
squeue -u $USER |
View jobs |