Want to Quickly Recall the Last Word or Last Argument from the Previous Command Line? Here’s How.



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 “!$“.

When I’m done with a file, I delete it, as in this example.

jason@linuxsvr:~$ mkdir restored
jason@linuxsvr:~$ cd !$
cd restored
jason@linuxsvr:~/restored$ unzip ~/Downloads/backup.zip
Archive: /home/jason/Downloads/backup.zip
extracting: Documents/meme.jpg
extracting: Documents/notes.txt
jason@linuxsvr:~/restored$ rm !$
rm ~/Downloads/backup.zip
jason@linuxsvr:~/restored$

In this next example, multiple commands are used to create and configure a user account. After the username is supplied the first time, it is recalled on subsequent command lines by using “!$“.

jason@linuxsvr:~$ sudo useradd -m -s /bin/bash sally
jason@linuxsvr:~$ sudo passwd !$
sudo passwd sally
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
jason@linuxsvr:~$ sudo chage -M 60 !$
sudo chage -M 60 sally
jason@linuxsvr:~$ sudo chage -l !$
sudo chage -l sally
Last password change : May 03, 2014
Password expires : Jul 02, 2014
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 60
Number of days of warning before password expires : 14
Linux repeat last command