• 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

How Much RAM Is Needed For Ubuntu PC

How To Find Large Files And Directories In Linux Command Line

How To Use Clear Command History In Linux Terminal

Linux Command To Check RAM Size In Ubuntu Terminal In GB

How To Install Proprietary Drivers In Linux Ubuntu Using Terminal

How To Shutdown Linux With A 15 Minute Delay And Message

Free AI Courses With Certificate For Beginners In India

Best AI Plugins For WordPress To Use In 2026

3 Commands To Check USB Connection In Linux Terminal

Linux Terminal Commands for Beginners With Examples

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

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