Unix notes

From 22126
Revision as of 15:36, 19 November 2025 by Mick (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction to UNIX

UNIX refers to a family of multitasking, multi-user operating systems that originated from AT&T Unix, first developed in 1969 at Bell Labs by Ken Thompson, Dennis Ritchie, and others. These systems have influenced many modern operating systems and are known for their stability, flexibility, and robust command-line interface.

Although UNIX may appear complex at first, it provides powerful tools for working with large datasets and automating workflows. In bioinformatics and NGS analysis, most tools run exclusively on the command line, making UNIX an essential skill.

Accessing UNIX

There are various ways to use UNIX depending on your operating system:

  • Windows: Download and install MobaXTerm.
  • Mac: macOS is UNIX-based; use the built-in Terminal application.
  • Linux: Most Linux distributions are UNIX-like and include a terminal by default.

Opening the terminal launches a shell where you can enter commands.

The Shell

The shell is the interface where you input commands. The prompt indicates the shell is ready for input. Examples include:

  • `aix4(s010178) $`
  • `interaction[pws]:/home/people/pws>`
  • `pws@antros:~$`

Different systems and shells (bash, zsh, etc.) may show different prompts.

Useful shortcuts:

  • Press TAB to autocomplete commands and file names.
  • Press Up/Down arrows to scroll through command history.
  • Press Ctrl + R to search command history.

File System Basics

In this guide, placeholders like `<filename>` indicate where you must substitute actual names (e.g., replace `<filename>` with `mydata.txt`).

Naming conventions:

  • Avoid spaces and special characters in file and directory names.
  • Safe characters include:
    • `abcdefghijklmnopqrstuvwxyz`
    • `ABCDEFGHIJKLMNOPQRSTUVWXYZ`
    • `0123456789.-_`
  • UNIX is case-sensitive: `MyFile.txt` and `myfile.txt` are different.
  • File extensions are optional but recommended for clarity.

Navigation commands:

  • `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 extremely careful with:

  • `rm` — deletes files permanently
  • `rm -rf` — recursively deletes directories (no undo!)

File Permissions

UNIX uses a permission system controlling access to files and directories.

Three user categories:

  • User — the file's owner
  • Group — users in the same group
  • Others — everyone else

Three permission types:

  • Read (`r`)
  • Write (`w`)
  • Execute (`x`)

Example from `ls -l`:

-rwxr--r-- 1 root sys 113520 Sep 5 14:15 good_program

This means:

  • User `root`: read, write, execute
  • Group `sys`: read
  • Others: read

Directory example:

drwxr-xr-x 6 gorm user 72 Jun 26 23:50 gorm_directory

Directory permissions:

  • Read (r) — list directory contents
  • Write (w) — create/delete files inside the directory
  • Execute (x) — enter the directory (without x, directory looks empty)

Common UNIX Commands

Most commands have options. Use `man <command>` to read manual pages.

Examples:

  • `man ls`
  • `man grep`

Notes:

  • Press q to exit `man`, `less`, and similar programs.
  • Press Ctrl + C to interrupt running commands.

For a complete list of commands used in this course, see the UNIX Commands Summary.

This guide provides the basics; you will become more comfortable with UNIX as you use it throughout the exercises and project work.