---
# System prepended metadata

title: Linux tutorial

---

##  WORKSHOP ON LINUX COMMAND LINE![datalab Nigeria](https://hackmd.io/_uploads/SybRnN9q0.png)

**Author:** **Daniel Adediran**

# Unix/Linux Tutorial
> ***With Command line, you can slay dragon and still be home by 6***

## 1. Basic Directory and File Commands

### Listing Contents of a Directory
- **Command:** `ls`
  - Lists files and directories in the current directory.
- **Command:** `ls -a`
  - Lists all files and directories, including hidden ones.
  
### Changing Directory
- **Command:** `cd directory`
  - Changes the current working directory to the specified `directory`.

### Creating Directories
- **Command:** `mkdir directory_name`
  - Creates a new directory with the specified `directory_name`.

### Displaying the Path of the Current Directory
- **Command:** `pwd`
  - Prints the absolute pathname of the current working directory.

### Exercise 1
- **Task:** Create a directory named `bioinformatics` and change to the directory.Then send the screenshot of your present directory via the zoom chat

---

## 2. Pathnames and Shell Shortcuts

### Understanding Pathnames
- **Command:** `ls ~/bioinformatics`
  - Lists the contents of the `bioinformatics` directory located in the home directory.

### Shell Shortcuts
- **Ctrl-A:** Jump to the start of the line.
- **Ctrl-E:** Jump to the end of the line.
- **Ctrl-K:** Delete everything from the cursor onwards.
- **Ctrl-W:** Delete the previous word.
- **Ctrl-Y:** Paste the last deleted text.
- **Ctrl-C:** Kill or exit a running process.
- **Ctrl-L:** Clear the screen.
- **Ctrl-R:** Search for previously executed commands.

---

## 3. File Manipulation

### Copying Files
- **Command:** `cp file1 file2`
  - Copies `file1` to `file2`.
- **Command:** `cp -R directory1 directory2`
  - Recursively copies `directory1` to `directory2`.

### Exercise 2
- **Task:** Create a backup of `genome.fasta` by copying it to a file named `genome_backup.fasta`

### Moving and Renaming Files
- **Command:** `mv file1 directory1/`
  - Moves `file1` to `directory1`.
- **Command:** `mv file1 file2`
  - Renames `file1` to `file2`.

### Removing Files and Directories
- **Command:** `rm file_name`
  - Removes the specified `file_name`.
- **Command:** `rmdir directory_name`
  - Removes the specified empty `directory_name`.

---

## 4. Displaying File Contents

### Viewing Files
- **Command:** `cat file_name`
  - Displays the contents of `file_name`.
- **Command:** `less file_name`
  - Displays the contents of `file_name` one page at a time.
- **Command:** `head file_name`
  - Displays the first ten lines of `file_name`.
- **Command:** `tail file_name`
  - Displays the last ten lines of `file_name`.

---

## 5. Searching Within Files

### Simple Searching with `less`
- **Command:** `/keyword` (within `less`)
  - Searches for `keyword` in the file currently opened with `less`.

### Searching with `grep`
- **Command:** `grep keyword file_name`
  - Searches for `keyword` in the specified `file_name`.

---

## 6. Downloading Files Using `wget` and `curl`

### Downloading Files with `wget`

- **Command:** `wget URL`
  - Downloads the file from the specified `URL` to the current directory.
  - Example: `wget http://plasmodb.org/common/downloads/release-9.0/Pfalciparum/fasta/PlasmoDB-9.0_Pfalciparum_BarcodeIsolates.fasta`

- **Command:** `wget -O output_name URL`
  - Downloads the file from `URL` and saves it with the specified `output_name`.
  - Example: `wget -O sequence_data.txt http://plasmodb.org/common/downloads/release-9.0/Pfalciparum/fasta/PlasmoDB-9.0_Pfalciparum_BarcodeIsolates.fasta`


### Downloading Files with `curl`

- **Command:** `curl -O URL`
  - Downloads the file from the specified `URL` and saves it with its original name.
  - Example: `curl -O URL`

- **Command:** `curl -o output_name URL`
  - Downloads the file from `URL` and saves it with the specified `output_name`.
  - Example: `curl -o sequence_data.txt URL`

- **Command:** `curl -L URL -o output_name`
  - Follows redirects and saves the file with the specified `output_name`.
  - Example: `curl -L https://bit.ly/example -o sequence_data.txt`

### Exercise 3
- **Task:** Download a file named `genome_data.txt` from `https://plasmodb.org/common/downloads/release-9.0/Pfalciparum/fasta/PlasmoDB-9.0_Pfalciparum_ESTs.fasta` using both `wget` and `curl`. Save the file with the name `genome_data.txt`.


---