Replace 8 Frequently Used Linux Commands!?
Tags: cli, linux, commands
Published: 2018-09-07 20:34:57

---
title: Replace 8 Frequently Used Linux Commands!?
published: true
tags: CLI, linux, commands
canonical_url: 
---

![coverimage](https://cdn-images-1.medium.com/max/1000/1*hcY3Bk8YY_1keCJW_b70Vw.jpeg)

Almost a decade ago, I started to touch the command-line interface (CLI). I’m now a nerdy CLI lover and I’m so obsessed by its efficiency. Therefore, I’m always trying out new command-line commands. From time to time, some commands are replaced by other improved ones in my daily workflow. Especially for some frequently used commands, it’s worth to find better alternatives.

Here is a list of improved commands I’d like to share with you:

### cd? z, up and fzf!

#### z

[z](https://github.com/rupa/z) is a very popular alternative command for jumping around. `z` doesn’t require any additional configurations. Although it works out of the box, you need just a little bit of patience. Because `z` has a “magic” algorithm based on “frequency” which can learn from the frequent vested directories after your `cd` around for a while.

An easy and quick example how to `z`:

```
~$ pwd
/home/foo/bar/one/two/three

~$ z tw
~$ pwd
/home/foo/bar/one/two

~$ z foo
~$ pwd
/home/foo

~$ z th
~$ pwd
/home/foo/bar/one/two/three
```


Want to know how “frequency” score looks like for all directories? Simply run command `z -l` will give you a list.

Want to clean some/all saved directories? Simply modify `$HOME/.z`.

#### up

[up](https://github.com/shannonmoeller/up) is an interesting command to replace `cd ..` and this ridicules one `cd ../../../../`

```
~$ pwd
/home/foo/bar/one/two/three

~$ up
~$ pwd
/home/foo/bar/one/two

~$ up 2
~$ pwd
/home/foo/bar

~$ up h
~$ pwd
/home
```

#### fzf

[fzf](https://github.com/junegunn/fzf) is a versatile command, which can be combined in other commands. With the help of its amazing searchability, it can be used to [“cd into the selected directory”](https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh):

[fzf example](https://kevcui.github.io/videos/fzf-example.svg)

### ls? exa!

[exa](https://github.com/ogham/exa) aims to be the modem replacement for `ls`. In my opinion, it did it. exa is really easy to use. Its options are straightforward:

![exa-example](https://kevcui.github.io/images/exa-example.jpg)

Here are my aliases:

```
alias ls='exa -s mod --git'
alias ll='exa -l -s mod --git --time-style=long-iso'
```

More options to tweak exa: [exa options](https://the.exa.website/docs/command-line-options)

### cat? bat!

[bat](https://github.com/sharkdp/bat) is a `cat` clone with syntax highlighting, line numbers and automatic paging (using `less` as the default pager). To display the contents of a file using `bat` looks like:

![bat-example](https://kevcui.github.io/images/bat-example.jpg)

It’s possible to customize the theme of syntax highlighting. It supports Sublime Text syntax format. Check these default themes to have some inspirations: [bat themes](https://github.com/sharkdp/bat/tree/master/assets/themes)

### grep? rg!

[rg](https://github.com/BurntSushi/ripgrep), ripgrep, is fast & furious. It has almost the same parameters of `grep` command, with improved output style and speed.

One main usage of `grep` for me is to find out which files contain some specific contents. An example to compare `grep` and `ripgrep`:

![grep-example](https://kevcui.github.io/images/grep-example.jpg)

![ripgrep-example](https://kevcui.github.io/images/ripgrep-example.jpg)

If you’re interested in how fast `rg` can be? Check this comparison: [rg vs. grep vs. ag. vs. ack…](https://github.com/BurntSushi/ripgrep#quick-examples-comparing-tools) Not sure if it’s still the case now. But overall, ripgrep is fast enough for my daily use.

### find? fd and fzf!

#### fd

[fd](https://github.com/sharkdp/fd) is a replacement for `find` focusing on user-friendly, with simplifying options of `find`. For example, I want to edit a file but I don’t remember what’s its full path actually is. Usually, I need to find its full path first and then edit it:

```
~$ find . -ipath "*how*exp*" -name "index.html"
./2017/04/17/how-i-do-exploratory-testing/index.html
~$ vi ./2017/04/17/how-i-do-exploratory-testing/index.html
```

Since I know the result will be only one file found, I can combine `vi` inside `find` command as well:

```
~$ find . -ipath "*how*exp*" -name "index.html" -exec vi {} \;
```

With `fd`, the command is more readable:

```
~$ fd -p 'how.*exp.*/index'
2017/04/17/how-i-do-exploratory-testing/index.html
```

#### fzf

[fzf](https://github.com/junegunn/fzf) has an extremely powerful fuzzy searchability. It can nest finding steps directly with another command. I bind the key [`ctrl-t` to enable fzf](https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh). As the same example as above, but with `fzf`, it’s a completely different story:

```
~$ vi (press ctrl-t)
```

[Another fzf example](https://kevcui.github.io/videos/fzf-example2.svg)

An alias to combine `vim` and `fzf`:

```
alias vif='vim $(fzf)'
```

### kill? fkill!

[fkill](https://github.com/sindresorhus/fkill), its **f** stands for “fabulously” (It’s definitely not the word I’m thinking in my mind 😉). Sometimes, `kill` some zombie processes is necessary. `fkill` can search a process and kill it interactively. It makes killing stylish:

[fkill example](https://kevcui.github.io/videos/fkill-example.svg)

### watch? loop!

_“UNIX’s missing loop command.”_ [loop](https://github.com/Miserlou/Loop) is designed to fill the gap. It works well to replace `watch`:

```
# monitor current directory and print file list every 6 seconds

# watch
~$ watch -n 6 ls -l

# loop
~$ loop -e 6s 'ls -l'
```

Moreover, `loop` has some awesome options to determine when to stop watching:

```
...
-c, --until-contains <until_contains> Keep going until the output contains this string
-r, --until-error <until_error> Keep going until the command exit status is non-zero, or the value given
-m, --until-match <until_match> Keep going until the output matches this regular expression
-t, --until-time <until_time> Keep going until a future time, ex. "2018-04-20 04:20:00" (Times in UTC.)
...
```

Example: stop watching when `stop-now` file is created and then open it in vim:


```
~$ loop -e 6s 'clear;date;ls -l' -c 'stop-now'; vi stop-now
```

[loop example](https://kevcui.github.io/videos/loop-example.svg)

Actually, using `loop` to replace `for` command is also promising and full of pleasure:

```
# create 10 markdown files: 0.md, 1.md ... 9.md

# for
~$ for ((i=0; i < 10; i++)); do touch ${i}.md; done

# loop
~$ loop -n 10 'touch ${COUNT}.md'
```

### man? tldr, pet and how2!

#### tldr

[tldr](https://github.com/tldr-pages/tldr) is a simplified collection of man pages. It returns some command snippets with practical examples:

![tldr-example](https://kevcui.github.io/images/tldr-example.jpg)

#### pet

[pet](https://github.com/knqyf263/pet) is a CLI snippet manager. It’s a handy tool to save some commands snippets which are easily forgotten. The idea is to use `pet` building own reference manuals.

#### how2

[how2](https://github.com/santinic/how2) takes another approach to search for the right command: it queries questions and answers from stackoverflow!

[how2 example](https://kevcui.github.io/videos/how2-example.svg)

In case the displayed answer is not what exactly you want, `how2` provides [the interactive mode](https://github.com/santinic/how2#usage) to select in a list of all relative questions and answers.

From now on, we can get confident to “save the world”!

![xkcd-tar](https://imgs.xkcd.com/comics/tar.png)

* * *

Share this list if you think it’s a good read for other CLI nerds. 💝

Drop me a message if you have other commands to recommend. ❤️