Reusing Previous Commands and Arguments

By now, you’re likely familiar with the history command, and you’ve probably used the Up arrow key to recall a previous command you’ve typed. And, way back in Chapter 1, Getting Your Feet Wet, you saw the !! command, which lets you run the previous command again. This works because of a feature called history expansion, which you can use to rerun previous commands, extract arguments, or even fix typos.

Let’s review the !! command before you get into the more advanced features. Use the ls -lh command to get a list of your home directory:

 $ ​​ls​​ ​​-lh
 total 44K
 drwxr-xr-x 2 brian brian 4.0K Oct 26 10:09 Desktop
 drwxr-xr-x 2 brian brian 4.0K Oct 26 10:07 Documents
 ...

Use the !! command to execute ...

Get Small, Sharp Software Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.