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,
![Zsh command to execute previous command Zsh command to execute the previous command](https://code2care.org/zsh/rerun-last-command-zsh-shell/images/Zsh command to execute previous command.gif)
Zsh command to execute previous command
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 ~ %
More Posts related to HowTos,
- [Fix] Error 1020 Cloudflare: Access was denied
- What is an Authorization Code Grant? OAuth 2.0
- Fix: psql: error: connection to server at localhost (::1) port 5432 failed: FATAL: database does not exist
- 100+ SEO Tips to improve your website search ranking
- How to submit website to dmoz directory
- How to check the version of NodeJS installed
- How to enter Rockstar Activation Code?
- Background task activation is spurious error - Windows 10, Office 2016, Office 365
- Angular CLI ng Error: You need to specify a command before moving on. Use --help to view the available commands
- cURL HTTP GET request command examples
- Fix - JioCinema Something Went Wrong Please Try Again Error 8001 while streaming IPL Cricket Live
- How to remove password from pdf file
- How to identify the version of IntelliJ
- Command: How to scp a file to remote server location?
- How to add Widgets to MacBook Desktop
- Setting up RSS feeds notifications within Outlook
- Fix - Website Connection timed out Error Code 522 (Cloudflare)
- How to fix: Please check your network connection (Retry)
- Fix: Could not connect to Redis at 127.0.0.1:6379: Connection refused
- Accept Only 0-9 Numbers RegEx Example
- How to create a New Project in Visual Studio Code (VS Code)
- Top 10 emerging breakthrough trending technologies
- Free Unlimited Calls from MTNL & BSNL Landlines from 1st May 2015
- [Error] zsh: command not found: mvn
- How to Scan iPhone for Virus? Is Antivirus it really required?
More Posts:
- [Fix] Office 365 Sharepoint One Drive Error: Something went wrong. This is a temporary issue - SharePoint
- How to Configure Eclipse keymap in IntelliJ IDE - Android-Studio
- [fix] command not found curl - cURL
- How to Kill service running on port using terminal command - HowTos
- Insert Auto Increment Value using PreparedStatement in Java JDBC - Java
- Fix: npm vs code eacces permission denied unlink /usr/local/bin/code - JavaScript
- How to change the default font and text size in Microsoft Excel for Mac - MacOS
- Youtube spacebar not working in search on macOS Safari - MacOS