1. Home
  2. Training Library
  3. Linux Administration Bootcamp Introduction | CSL4 V2 A3.1 |

Reuse the Last Item from the Previous Command


Linux Administration Bootcamp
Installing and Connecting to a Linux System
Linux Boot Process and System Logging
Disk Management in Linux
User Management in Linux
Shell Scripting with Linux
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