Basic UNIX notes
Introduction to UNIX
UNIX refers to a family of multitasking, multi-user operating systems that originated from AT&T Unix (Bell Labs, 1969). Many modern operating systems are UNIX-like and inherit its core principles of stability, flexibility, and powerful command-line tools.
Although UNIX may appear complex at first, it is essential in bioinformatics and NGS analysis. Most tools you will use in this course (and in real research) run exclusively on the command line.
Accessing UNIX
You can access a UNIX shell in several ways:
- Windows: Install MobaXTerm (recommended).
- Mac: macOS is UNIX-based; use the built-in Terminal.
- Linux: Most Linux distributions include a terminal by default.
Opening the terminal launches a **shell**, where you enter commands.
The Shell
The shell is your interface to the operating system. A prompt shows that it is ready for input. Examples:
- `aix4(s010178) $`
- `interaction[pws]:/home/people/pws>`
- `pws@antros:~$`
Prompts may differ between systems and shell types (bash, zsh, etc.).
Useful shortcuts:
- Press TAB to autocomplete commands and file names.
- Press ↑/↓ to scroll through command history.
- Press Ctrl + R to search your command history.
- Press Ctrl + C to cancel a running command.
- Press q to exit `less`, `man`, and similar programs.
File System Basics
In this guide, placeholders like `<filename>` mean “replace this with your file name” (e.g., `mydata.txt`).
Naming conventions:
- Avoid spaces and special characters in file/directory names.
- Safe characters:
- `a-z`
- `A-Z`
- `0-9.-_`
- UNIX is case-sensitive: `file.txt` ≠ `File.txt`
- File extensions are optional but recommended.
Navigation:
- `pwd` – show current directory
- `ls -l` – list files with details
- `cd <directory>` – change directory
- `mkdir <name>` – create directory
Viewing files:
- `cat <file>`
- `less <file>`
- `head <file>`
- `tail <file>`
Be careful with:
- `rm <file>` – permanently deletes files
- `rm -rf <directory>` – recursively deletes directories (NO UNDO)
File Permissions
Each file has permissions for:
- User – the owner
- Group – users in the same group
- Others – everyone else
Permissions:
- Read (r)
- Write (w)
- Execute (x)
Example from `ls -l`:
-rwxr--r-- 1 root sys 113520 Sep 5 14:15 good_program
Directory example:
drwxr-xr-x 6 gorm user 72 Jun 26 23:50 gorm_directory
Directory meanings:
- r – list directory contents
- w – create/delete files inside
- x – enter the directory
Basic Input/Output and Pipes (brief introduction)
Every UNIX command interacts with three “streams”:
- stdin – input (keyboard by default)
- stdout – normal output
- stderr – error messages
You can redirect them:
- Redirect stdout: `command > out.txt`
- Redirect stderr: `command 2> errors.txt`
- Redirect stdin: `command < input.txt`
- Append instead of overwrite: `>>`
- Pipe output of one command into another:
`command1 | command2`
Examples:
ls | wc -l # count files grep HUMAN ex1.acc | sort | uniq -c
For a deeper explanation of pipes, file descriptors, and redirection, see the advanced page: Advanced UNIX and Pipes
Common UNIX Commands
Use `man <command>` to read manual pages.
Examples:
- `man ls`
- `man grep`
You will learn additional commands during the exercises and project work.
For a more complete list, see the UNIX Commands Summary.