Unix notes: Difference between revisions

From 22126
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
=== Introduction to UNIX ===
=== Introduction to UNIX ===
UNIX refers to a family of multitasking, multi-user computer 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. Despite appearing complex at first, using UNIX-based systems efficiently provides a powerful way to manage and operate computing tasks.
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 ===
=== Accessing UNIX ===
There are various ways to use UNIX depending on your operating system:
There are various ways to use UNIX depending on your operating system:


* '''Windows''': Download and install [MobaXTerm](https://mobaxterm.mobatek.net/).
* '''Windows''': Download and install [https://mobaxterm.mobatek.net/ MobaXTerm].
* '''Mac''': macOS is built on a UNIX-based system, so you can use the built-in Terminal application.
* '''Mac''': macOS is UNIX-based; use the built-in Terminal application.
* '''Linux''': Most Linux distributions are based on UNIX, and the terminal is readily available.
* '''Linux''': Most Linux distributions are UNIX-like and include a terminal by default.


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


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


The shell is the interface where you input commands. The prompt, which varies across systems, indicates that the shell is ready for your input. Examples of prompts include:
* `aix4(s010178) $`
* `aix4(s010178) $`
* `interaction[pws]:/home/people/pws>`
* `interaction[pws]:/home/people/pws>`
* `pws@antros:~$`
* `pws@antros:~$`


Different shells and operating systems may have unique prompts and behaviors.
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 ===
=== File System Basics ===
In this guide, placeholders like `<something>` indicate where you should input specific text. For example, `<filename>` should be replaced with an actual file name, such as `MyFile.txt`.
In this guide, placeholders like `<filename>` indicate where you must substitute actual names (e.g., replace `<filename>` with `mydata.txt`).


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


* Remember, UNIX is case-sensitive: `MyFile.txt` and `myfile.txt` are treated as distinct files.
Navigation commands:
* Although file extensions (like `.txt` or `.doc`) aren't required, using them helps identify file types.
* `pwd` — show current directory
* `ls -l` — list files with details
* `cd <directory>` — change directory
* `mkdir <name>` — create directory


=== File Permissions ===
Viewing files:
UNIX has a permission system that controls file and directory access:
* `cat <file>`
* Three categories of users:
* `less <file>`
** '''User''': The file's owner.
* `head <file>`
** '''Group''': Users in the file's group.
* `tail <file>`
** '''Others''': Everyone else.
* Three types of permissions:
** '''Read''' (`r`): View the contents of the file.
** '''Write''' (`w`): Modify the file.
** '''Execute''' (`x`): Run the file as a program.


For example, running `ls -l` might yield:
Be extremely careful with:
* `rm` — deletes files permanently
* `rm -rf` — recursively deletes directories ('''no undo!''')


    -rwxr--r-- 1 root sys 113520 Sep 5 14:15 good_program
=== File Permissions ===
UNIX uses a permission system controlling access to files and directories.


This indicates that `good_program` is a file with:
Three user categories:
* '''User (`root`)''': Read, write, and execute permissions.
* '''User''' — the file's owner
* '''Group (`sys`)''': Read permission only.
* '''Group''' — users in the same group
* '''Others''': Read permission only.
* '''Others''' — everyone else


For directories, a leading `d` denotes a directory:
Three permission types:
* '''Read''' (`r`)
* '''Write''' (`w`)
* '''Execute''' (`x`)


    drwxr-xr-x 6 gorm user 72 Jun 26 23:50 gorm_directory
Example from `ls -l`:
<pre>
-rwxr--r-- 1 root sys 113520 Sep 5 14:15 good_program
</pre>


This indicates that `gorm_directory` is a directory with:
This means:
* User `root`: read, write, execute
* Group `sys`: read
* Others: read


* '''User (`gorm`)''': Read, write, and execute permissions.
Directory example:
* '''Group (`user`)''': Read and execute permissions.
<pre>
* '''Others''': Read and execute permissions.
drwxr-xr-x 6 gorm user 72 Jun 26 23:50 gorm_directory
</pre>


'''Note on Directories''':
Directory permissions:
* '''Write (`w`)''': Allows creating or deleting files within the directory.
* '''Read (r)''' — list directory contents
* '''Execute (`x`)''': Allows listing the directory's contents. If execute permission is missing, the directory will appear empty.
* '''Write (w)''' — create/delete files inside the directory
* '''Execute (x)''' — enter the directory (without x, directory looks empty)


=== Common UNIX Commands ===
=== Common UNIX Commands ===
Most commands have options. Use `man <command>` to read manual pages.


Most UNIX commands come with options that modify their behavior. You can use the `man` command to read manual pages for detailed explanations:
Examples:
 
* `man ls`
    man <command>
* `man grep`
 
 
For example, `man ls` provides detailed information about the `ls` command.


'''Note''':
Notes:
* Many commands can be stopped with `Ctrl + C`.
* Press '''q''' to exit `man`, `less`, and similar programs.
* Commands like `less` and `man` display information and wait for your input. Press `q` to exit these commands.
* Press '''Ctrl + C''' to interrupt running commands.


For a summary of common UNIX commands and their usage, see the [https://teaching.healthtech.dtu.dk/unix/index.php/Commands_summary UNIX Commands Summary].
For a complete list of commands used in this course, see the
[https://teaching.healthtech.dtu.dk/unix/index.php/Commands_summary UNIX Commands Summary].


This guide is an introduction to the UNIX system, designed to help you understand the basics and gradually become proficient in using the command line.
This guide provides the basics; you will become more comfortable with UNIX as you use it throughout the exercises and project work.

Latest revision as of 15:36, 19 November 2025

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.