Linux Basic Commands
12. history
history Command in Linux
The history command shows a list of all previously run commands in the terminal.
Itβs very useful to recall or repeat past commands.
πΉ Syntax:
history
πΉ Example:
history
π Output:
1 ls2 pwd3 cd /home/ashwin4 mkdir test5 history
This shows:
-
Line numbers for each command
-
The exact command you typed earlier
πΉ Useful Options & Examples:
β 1. Run a previous command by number
!3
π Runs the 3rd command from the history (in this case: cd
/home/ashwin)
β 2. Search your command history
history | grep mkdir
π Finds all mkdir commands you've used before.
β 3. Repeat the last command
!!
π Runs the most recent command again.
β 4. Clear your command history
history -c
π Clears all saved history for the current session.
β 5. Save history to a file
history > my_history.txt
π Saves your full command history into my_history.txt.
Try with Linux Practice