Reuse the Last Item from the Previous Command
Start course
7h 28m

In this course, you will learn how to install a Linux system and connect to it, whether that be on Mac or Windows.


Many times workflows can revolve around a single item. That item might be a file, a directory, a user or even something else. Time and time again, I find myself needing to run another command against the last item on the previous command line. To access that item in your current command, use bang dollar or exclamation mark dollar sign. Let's look at an example here. I create a directory and what I typically want to do after I create a directory is change into that directory. So I can access the last item on the command line, on the previous command line, by using bang dollar.

So now I'm in that directory that I created. Let's do this. I have a backup file here. I'm going to unzip. And then once I'm done with that, I want to delete it. So a shortcut again, is use bang dollar. And also, sometimes I find myself making mistakes so I could type a misspelling and I realized, Oh, that's not good. Let me get rid of that." And then, I can use that to correct my spelling as well. Here's an example where we're going to run multiple commands to create and configure a user account. I'll supply the user to this command here. I'll just call this account, Jimmy. That created the user. 

Now, what I want to do is set a password for that user. And again, to access Jimmy, I just type bang dollar in this instance. I'll give him a really secure password of Jimmy. And then I want to make sure that he changes his password at least every 60 days. So I'll run this command. Oops, typo there. And let me make sure I got that right. Let me just list his properties on this account there.

To recap, you can use the last item on the previous command using bang dollar or exclamation mark dollar sign. This little shortcut comes in really handy when you're working on a particular item and you need to run multiple commands against that item.

About the Author
Learning Paths

A world-leading tech and digital skills organization, we help many of the world’s leading companies to build their tech and digital capabilities via our range of world-class training courses, reskilling bootcamps, work-based learning programs, and apprenticeships. We also create bespoke solutions, blending elements to meet specific client needs.