Learn Linux in 180s - history command

David Bombal · Beginner ·☁️ DevOps & Cloud ·1mo ago
Skills: Linux & CLI90%

Key Takeaways

Explains how to use the Linux history command to reverse search, rerun previous entries, and fix sudo permissions

Full Transcript

It's important that you learn Linux in 2026. The history command allows me to see a history of commands that I've used. I used tab to auto complete that command. At this point, I've used 235 commands. If I type man history, press tab here, that shows me the manual pages of the history command, which gives me a lot of options. But again, if I type history, notice the number of commands that I've used has increased. If I want to reuse a command, I can use exclamation mark here, 223, and that will rerun that command. So, I'll just do that again because it wasn't so clear. Let's use 227. That runs this command, which then shows the output of this file called file one. I could say, let's run command 231 in this example, which shows me the output of file two. So, again, if I use 230, that runs this command. 231 runs that command. I can use control R to do a reverse search for a command in my history. So, if I use cat, that was the last command that I used that contained the word cat. So, if I type history here, you can see I used that command there. Control R as an example, let's use the command CD. The last CD command that I used was that. If I scroll up, you can see it's there. So, it's doing a reverse search through the output. I'll just go back to my home directory. So, again, there are a lot of options with the history command. Have a look at the man pages if you want to learn more. I've already shown you this option where you can run a specific command again, but there are many, many options with commands like this. Again, in Linux, there are many options available to you. But I think for most of us, we're just going to use history and then run a specific command from our history. Now, a really nice option with history is let's say you use a command like apt update to update references on your Linux machine. Here, it's telling us we can't do that because we need to use sudo privileges. So, I can simply type sudo {exclamation} {exclamation} and that will rerun the command with sudo privileges. So, now I've used sudo apt update instead of apt update. So, now it's asking for my password. I can put that in and it runs the command successfully. So, don't forget to use the option sudo {exclamation} {exclamation} if you forgot to put sudo in the beginning of your command. I hope you've learned something, but let me know in the comments your favorite Linux commands.

Original Description

Master the Linux terminal in 2026 with these essential history command shortcuts. Learn how to reverse search, rerun previous entries, and fix sudo permissions instantly. #history #linux #terminal
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

Up next
How to Code with Distrobox on the Steam Deck
Ian Wootten
Watch →