• Skip to secondary menu
  • Skip to main content
  • Skip to primary sidebar

Python and R Tips

Learn Data Science with Python and R

  • Home
  • Python
  • Pandas
    • Pandas 101
  • tidyverse
    • tidyverse 101
  • R
  • Linux
  • Conferences
  • Python Books
  • About
    • Privacy Policy
You are here: Home / Linux Tips / history lookup / Two Most Useful Commands, If You Live On The Linux/MacOS Terminal

Two Most Useful Commands, If You Live On The Linux/MacOS Terminal

October 21, 2011 by cmdlinetips



Do you use the linux/Mac OS X terminal a lot? If yes, you must have a few most useful commands. The commands that help you move around terminal fast and gives you the super power to look up your history real fast will be handy on every day use. Calling them as the “Most Useful Ever” may be a bit of exaggeration. But, If you did not know about these linux commands before you will be thankful for these commands.

How to Get Back to Previous Working Directory or How to Toggle between Two Directories?

Moving between directories is one of the frequent operations that one will be doing on the terminal. Often, you will end up with real deep directory structure and want to go back to the previous working directory. If the previous directory that worked was your home directory, you can just type “cd” to get back to your home directory irrespective of where you are now.

However, often you may want to go back to other directories. Naive way to do is retype all the long path to go where you want. Terminal also offers the best solution to go back to the previous working directory. And the command to do that is just

“cd -“.

Is not that short and very sweet?

How to Look Up Your History Real Quick and Execute Commands from History?

If you spend a lot time on a Linux/MacOS X terminal, frequently you will be executing commands that you used before. The Linux shell that you use may offer simple solution like using up arrow keys to go back to the command you used before. If you know little bit about history, you might even cut down the number of keystrokes by using exclamation “!” and the first few letters of the command that you used before. However, there may be many commands that look similar or you may have to exact remember what you typed.

Possibly the most convenient way to look up your history is to use the “reverse-i-search”. Type

Ctrl and r

in the terminal to invoke the “reverse-i-search”. After typing “Ctrl – r”, you will see

(reverse-i-search)`’:

Then you type parts of the command that you wanted to reuse to look up in your history. As you type, “Reverse-i-search” will display a command that contains what you typed. The best part is, if the command it returns is not the one you want, type Ctrl-r and it will search back in the history and give another command that matched your query.

For example, if you look for a “scp” command that you used before, type “Ctrl-r” and “scp” to get the most recently used command containing scp. If the first result isn’t the one that you wanted, type Ctrl r to keep get another command that matahces your query in your history.

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related posts:

Default ThumbnailBash tip: Search through history using the up and down arrows Default ThumbnailBasic Linux/Mac OS X Commands that Help You to Get Started Default ThumbnailEleven IPython Keyboard Shortcuts to Move Around Easily Tips to Get Started with Screen, the Terminal Multiplexer

Filed Under: history lookup, Linux Tips, Mac OS X Tips, Uncategorized Tagged With: Linus Tips, Mac Os X Tips, Reverse Search

Primary Sidebar

Subscribe to Python and R Tips and Learn Data Science

Learn Pandas in Python and Tidyverse in R

Tags

Altair Basic NumPy Book Review Data Science Data Science Books Data Science Resources Data Science Roundup Data Visualization Dimensionality Reduction Dropbox Dropbox Free Space Dropbox Tips Emacs Emacs Tips ggplot2 Linux Commands Linux Tips Mac Os X Tips Maximum Likelihood Estimation in R MLE in R NumPy Pandas Pandas 101 Pandas Dataframe Pandas Data Frame pandas groupby() Pandas select columns Pandas select_dtypes Python Python 3 Python Boxplot Python Tips R rstats R Tips Seaborn Seaborn Boxplot Seaborn Catplot Shell Scripting Sparse Matrix in Python tidy evaluation tidyverse tidyverse 101 Vim Vim Tips

RSS RSS

  • How to convert row names to a column in Pandas
  • How to resize an image with PyTorch
  • Fashion-MNIST data from PyTorch
  • Pandas case_when() with multiple examples
  • An Introduction to Statistical Learning: with Applications in Python Is Here
  • 10 Tips to customize ggplot2 title text
  • 8 Plot types with Matplotlib in Python
  • PCA on S&P 500 Stock Return Data
  • Linear Regression with Matrix Decomposition Methods
  • Numpy’s random choice() function

Copyright © 2025 · Lifestyle Pro on Genesis Framework · WordPress · Log in

Go to mobile version