Awesome Terminal Tricks to Boost Your Productivity

Jul 6, 2020 · 2 mins read
Awesome Terminal Tricks to Boost Your Productivity

If you are glued to the terminal, you may want to use the following tricks to improve your productivity. These have been a life saver to me. If you’re not a terminal user, these tricks will make you love the terminal again.

Contents:

Useful aliases

Copy the lines starting with alias to your ~/.bashrc file to enable them.

1. Open a file in GUI mode

alias open='xdg-open &>/dev/null'
$ open home/        # opens home directory

2. Copy output of a command

# Install xclip (apt-get install xclip)
alias c="xclip -selection clipboard"
$ ls | c            # copies output of ls (now you can paste)

3. Show your public ip

alias myip='curl ifconfig.me'
$ myip              # outputs your ip

4. Go back in directories

alias ..='cd ../'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'

5. Use bat instead of cat

alias cat=bat       # make sure bat is installed
$ cat myfile.txt    # apt-get install bat

6. No need to type sudo everytime now when installing

alias apt-get='sudo apt-get'

7. Start a http server

alias www='python3 -m http.server'
$ www               # starts server in the current directory

Command editing hacks

Ctrl + x + e      Edit big cmds in editor  
Ctrl + a          Go to beginning of cmd
Ctrl + e          Go to end of cmd  
Ctrl + w          Erase entire word  
Ctrl + ←/→        Move faster within the cmd

Running past commands

1. Run the previously executed command

$ !!
$ sudo !! # previously executed command with sudo

2. Run the last command starting with xxx

$ !xxx
# shows recent command based on the typed characters
$ Ctrl + r [now type chars]   

4. Search by filtering entire search history

$ history | grep "xxx"        # searches for commands including xxx

Useful commands

1. Know when internet connection is up

$ ping 8.8.8.8 -a     # Makes periodic beeps when there is connectivity

2. Show open ports

$ sudo lsof -ni

3. Live read log files

tail -f /var/log/my-app/my-app.log | grep ERROR

4. Simple image editing

# Must have imagemagick installed (apt-get install imagemagick)

# Append multiple images horizontally
convert +append input1.jpg input2.jpg output.jpg

# Append multiple images vertically
convert -append input1.jpg input2.jpg output.jpg

# Reize image
convert -resize 50% input.png output.png

# Add border to image
convert input.gif -shave 1x1 -bordercolor black -border 1 output.gif

5. Easily go to last directory

# Takes you to the previous directory you were in
cd -

Sharing is caring!