The reference module: the commands you will use 90% of the time. The goal is to build muscle memory so the terminal feels like a natural extension of your thought process, rather than a barrier to your research.
2.1 Navigation
Linux uses a hierarchical tree structure starting at the root (/).
# Print working directory — where am I?
pwd
# List files
ls # basic listing
ls -l # long format (permissions, size, date)
ls -la # include hidden files (dotfiles like .bashrc)
ls -lh # human-readable file sizes (KB, MB, GB)
# Change directory
cd /path/to/dir # absolute path
cd relative/path # relative path
cd ~ # home directory
cd .. # parent directory
cd - # previous directory (toggle)
# Note: extremely useful when jumping between
# a data directory and a script directory
2.2 File Operations
Creating, Copying, Moving, Renaming
# Create
touch file.txt # create empty file (or update timestamp)
mkdir mydir # create directory
mkdir -p a/b/c # create nested directories (parent/child/grandchild)
# Copy
cp file.txt backup.txt # copy file
cp -r mydir/ mydir_backup/ # copy directory recursively
# Move / Rename
mv file.txt newname.txt # rename
mv file.txt /other/path/ # move
Deleting
There is no trash can in the terminal. Deletion is permanent.
rm file.txt # delete file
rm -r mydir/ # delete directory recursively
rm -ri mydir/ # interactive — asks before every file
Wildcards (Globbing)
*matches anything (e.g.,*.csvmatches all CSV files)?matches exactly one character (e.g.,file?.txtmatchesfile1.txtbut notfile10.txt)
2.3 Viewing & Searching
Viewing Files
# View entire file
cat file.txt # dump whole file to terminal (bad for large files)
less file.txt # paginated view (q to quit, / to search)
# View parts
head file.txt # first 10 lines
head -n 20 file.txt # first 20 lines
tail file.txt # last 10 lines
tail -f logfile.log # follow a log file in real-time
grep — The Search Tool
grep filters input line-by-line. Essential for bioinformatics (finding specific sequences, counting FASTA records, etc.).
# Basic search
grep "pattern" file.txt
# Case-insensitive
grep -i "pattern" file.txt
# Show line numbers
grep -n "pattern" file.txt
# Recursive search (all files in current directory)
grep -r "TODO" .
# Invert match (lines that do NOT match)
grep -v "error" log.txt
# Count matching lines
grep -c ">" sequences.fasta
2.4 Permissions
Every file has a mode string (e.g., -rwxr-xr--) defining who can do what.
The Bits
| Symbol | Meaning | Octal Value |
|---|---|---|
r |
Read | 4 |
w |
Write | 2 |
x |
Execute | 1 |
Changing Permissions (chmod)
# Symbolic mode (easier to read)
chmod +x script.sh # add execute for everyone
chmod u+w file.txt # add write for owner (u=user)
chmod go-r private.key # remove read for group and others
# Numeric mode (faster to type)
chmod 755 script.sh # rwx (7) for owner, r-x (5) for group/others
chmod 644 file.txt # rw- (6) for owner, r-- (4) for group/others
chmod 600 private.key # rw- (6) for owner, --- (0) for group/others
2.5 Pipes & Redirection
Redirection
| Operator | Behavior |
|---|---|
> |
Overwrite output to a file |
>> |
Append output to the end of a file |
2> |
Redirect stderr (errors) only |
echo "Analysis Complete" > status.txt # creates/overwrites file
echo "Error found" >> log.txt # appends to file
Pipes (|)
Passes the stdout of the left command to the stdin of the right command.
# Count number of Python files
find . -name "*.py" | wc -l
# Check for errors in the last 50 lines of a log
tail -n 50 app.log | grep "Error"
# Unique sorted values (classic combo)
cat data.txt | sort | uniq
# This is the Unix philosophy in action — small tools chaining
# together to solve complex problems without a custom script.