5 Helpful Linux Shell Tricks You May Not Know About

These are just 5 helpful Linux tricks I’ve picked up in my career and thought would be nice to share, in case there are others that don’t know about them!

  • Did you know that you can use cd without any arguments to go back to your home directory?
  • You can use cd - to go back to the previous directory you were in! If you do it again after the first time, you can switch back and forth.
  • On a similar note, there is actually a directory stack. You can use pushd instead of cd to go to another directory and add it on to your stack. You can see your stack with dirs and use popd to take the topmost directory off the stack and go back to the directory before it.
  • You can use history to see your command history. It should give you a list of numbers and corresponding commands. Then you can use !(the number) to repeat a command. For example, in the following scenario:
    $ history
    101 ls
    102 ssh errietta@errietta-laptop
    103 cd ~/Downloads

    In this scenario, you’d use !103 to repeat the command cd ~/Downloads.

  • You can use CTRL-R to search backwards in your command history. I’ve found this incredibly helpful! You could, for example, press CTRL-R followed by the word git to find the previous git push command in your history instead of typing the whole command in again. Save seconds from your day!

I’ve also made a video if you want to see those tricks in action! Enjoy!

Leave a Comment

Your email address will not be published. Required fields are marked *