If you want to execute the zsh last command that you ran, the easiest way would be by pressing the up arrow key on your keyboard, the last command is pulled up on your prompt and you press enter. But do you know there is another way in which you can run the previous command using a command? Simply type to exclamation marks !! - this will execute the last executed command on your Zsh shell. Let's see some examples,

As you can see, when I typed !! the previous command that was clear was executed again. In the next example, it was the who command. Also notice that when you run the double exclamation command it displays the command as text in the first line outputted and then the result of the command,
code2care@mac ~ % !!
ls -ltrh
total 0
drwxr-xr-x+ 4 code2care staff 128B Jan 2 23:03 Public
drwx------+ 4 code2care staff 128B Jan 2 23:28 Pictures
drwxr-xr-x 4 code2care staff 128B Jan 17 16:16 ClassRoom
drwx------@ 75 code2care staff 2.3K Feb 13 16:04 Library
drwx------@ 3 code2care staff 96B Feb 13 16:04 Applications
drwxr-xr-x 5 code2care staff 160B Feb 15 22:32 IdeaProjects
drwx------@ 13 code2care staff 416B Mar 6 18:01 Documents
drwx------+ 7 code2care staff 224B Mar 13 22:42 Music
drwx------ 6 code2care staff 192B Mar 20 16:54 Movies
drwx------+ 18 code2care staff 576B Apr 3 12:41 Downloads
drwx------@ 8 code2care staff 256B Apr 3 13:27 Desktop
code2care@mac ~ %
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!