history command is used to view the previously executed command. This feature was not available in the Bourne shell. Bash and Korn support this feature in which every command executed is treated as the event and is associated with an event number using which they can be recalled and changed if required. These commands are saved in a history file. In Bash shell history command shows the whole list of the command.
Here, the number(termed as event number) preceded before each command depends on the system. You may get different numbers while executing on your own system.
- To show the limited number of commands that executed previously as follows:
$ history 5
Note: The command can be executed using event number also.
- To print command before executing so that a wrong command does not get executed use :p after event number of command.
- This command can also be used along with grep.
history | grep chpasswd
- The most recent command can be viewed using !!
- Suppose if the command has to be executed without being stored variable HISTFILE has to be unset.
- The command can also be executed using a part of the command.
- History can also be removed using history -d event_number
history -d 1996
- The whole history can be removed using history -c option.
- How to get history changes notification via history.pushState() method ?
- The complete History of Java Programming Language
- How to Delete Google Chrome Browsing History?
- 'IPCS' command in Linux with examples
- select command in Linux with examples
- Sed Command in Linux/Unix with examples
- ZIP command in Linux with examples
- SORT command in Linux/Unix with examples
- Cat command in Linux with examples
- Head command in Linux with examples
- Tail command in Linux with examples
- wc command in Linux with examples
- tar command in Linux with examples
- atrm command in Linux with examples
- bc command in Linux with examples
- AWK command in Unix/Linux with examples
- tr command in Unix/Linux with examples
- mv command in Linux with examples
- Paste command in Linux with examples
- comm command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.