• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / How To / Re Execute The Previous Command In Linux Ubuntu Command Line

Re Execute The Previous Command In Linux Ubuntu Command Line

By Sourabh / April 20, 2026 Category: How To, Ubuntu

Know which command is used to repeat the last command in Unix Systems. Here is how to get previous command in Linux Ubuntu command line.

Let us learn more about re-executing previous commands.

Method 1 – Run Last Command using Exclamation Marks

To execute the last executed command, just type double exclamation marks, and press ENTER key in the terminal:

$ !!

This will execute the last command.

You can also run the command as root user. Simply add sudo in-front of !! to execute the last command as root user.

$ sudo !!

Or

$ su -c "!!"

Method 2 – Use Hyphen Symbol with Command Prefix Numbers

If you want to run a specific command which was executed lastly (but you don’t know when, was it the last command or the second last command or the third last command).

To execute the previous command, run the following:

$ !-1

Note that the number 1 denotes here the last executed command, similarly, !-2 will run the second last command, !-3 will run the third last, !-4 will run the fourth last command, and so on.

In this case you can use the history command to re-execute a certain command using hyphen symbol with the command prefix number.

When you run the history command you see the list of previously executed commands with their corresponding command number (prefix). Note down the prefix of the command and to re-execute the command with hyphen.

Method 3 – Re-execute Previous Commands Using CTRL+P

You can search the command line history using CTRL+P. Press CTRL+P key to search through the command line history and once you find the command you want to execute, press ENTER key.

This is also another way to repeat the last executed command. You can use the fc command is used to list, edit and re-run the previously entered command.

And, that’s all. I hope you shall find this article useful and these methods will help yo in future.

Primary Sidebar

Latest Posts

Downlaod Ubuntu 26.10 Stonking Stingray

How To Shutdown Linux With A 15 Minute Delay And Message

Using Linux Terminal How To Get Total Disk Size In GB

Count And Find Number Of Files In A Linux Directory Using Command

Check How Many Users Are Created In Linux Ubuntu

How To Check User Permissions In Linux Using Command

Check Which Folder Is Taking More Space In Ubuntu Linux

How to Install Claude Desktop App in Ubuntu Linux

Job Scheduling Using At Command In Linux With Examples

How To Check Permissions Of A Directory In Linux Command

© 2026 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap