# Zsh hints

Return to previous directory

```
-
```

you can type `d` to see the first ten items in the list and the number to switch to it:

```
$ d
0       /usr/local
1       ~
2       /var/log
3       /var/opt
4       /usr/bin
5       /usr/lib
6       /tmp
7       ~/Projects/Opensource.com/zsh-5tips
8       ~/Projects
9       ~/Projects/ansible
$ pwd
/usr/local
$ 6
/tmp
$ pwd
/tmp
```

typing double bangs (`!!`) brings back the last command anywhere in the line. This is useful, for instance, if you forgot to type `sudo` to execute commands that require elevated privileges:

```
$ less /var/log/dnf.log
/var/log/dnf.log: Permission denied
$ sudo !! 
$ sudo less /var/log/dnf.log
```

Quick reference:

* Oh My Zsh's Command-Line Interface (CLI): `omz`. Run `omz --help` for available commands.
* To **update** Oh My Zsh: `omz update`.
* To **uninstall** it: `uninstall_oh_my_zsh`.
* To apply changes made to `.zshrc`: `omz reload` (this just runs `exec zsh`). [**Do NOT run `source ~/.zshrc`**](https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#how-do-i-reload-the-zshrc-file).

### Commands

| Command         | Description                                                                                |
| --------------- | ------------------------------------------------------------------------------------------ |
| `alias`         | List all aliases                                                                           |
| `take` / `mkcd` | Create a new directory and change to it, will create intermediate directories as required. |
| `zsh_stats`     | Get a list of the top 20 commands and how many times they have been run.                   |

### Directory

| Alias      | Command                                    |
| ---------- | ------------------------------------------ |
| `md`       | `mkdir -p`                                 |
| `rd`       | `rmdir`                                    |
| `cd` / `~` | `cd` to your home directory                |
| `..`       | `cd ..`                                    |
| `...`      | `cd ../..`                                 |
| `....`     | `cd ../../..`                              |
| `.....`    | `cd ../../../..`                           |
| `/`        | `cd /`                                     |
| `d`        | `dirs -v` (lists last visited directories) |
| `cd +n`    | Switch to directory number `n`             |
| `-`        | `cd` to last visited directory             |
| `1`        | `cd -1`                                    |
| `2`        | `cd -2`                                    |
| `3`        | `cd -3`                                    |
| `4`        | `cd -4`                                    |
| `5`        | `cd -5`                                    |
| `6`        | `cd -6`                                    |
| `7`        | `cd -7`                                    |
| `8`        | `cd -8`                                    |
| `9`        | `cd -9`                                    |

<https://github.com/ohmyzsh/ohmyzsh/wiki/Cheatsheet>

\ <br>
