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

Rerun a Command Starting with a String


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.


To run the most recent command that begins with a given string, use an exclamation mark followed by that string. For example, to run the last command that started with a D, type exclamation mark D enter. Specify as much of the string as required to make it unique. If you have several commands in your recent history that began with the letter D you can add additional characters, like exclamation mark D U or exclamation mark D F.

I find myself using this technique to get a status, perform some work that might affect that status. and then to recheck that status again. Here's an example where data is being copied to a file system that where the disc usage is being checked. Let's change into a directory of our plan to restore some data. I'll check the disc usage with a df command and now I will extract some data into this directory. And then using exclamation mark D, I will recheck the status. You can see that about 400 megabytes of data was extracted into this file system.

Here's an example that demonstrates a situation where more than just one character of a string is required to recall the desired command. Let's create a directory for my fictitious application called myapp. Let's create a user for this application. And we'll make that application owner the owner of the directory here. And if I run an exclamation mark M, the most recent command that begins with M is mkdir. So it will run mkdir myapp.

Now, if I want to run C H O W N to change the ownership I will have to specify C H O if I just specify C, cd will execute. I specify C H, chmod will execute. So to run chown I need to specify exclamation mark C H O and then if I want to run the chmod command I will specify just enough as required to make that unique. I could specify more if I wanted, for instance.

About the Author