history (Check Command History)
The history
command is used to display commands you run on the shell. This command is useful when you want to check what you have done before or reuse the same command you executed before.
Display a command history
To display a history of commands, run history
without any argument. The history
command will display up to 1,000 commands.
history
:
563 echo $ABC
564 sudo chmod u+x variable_parent.sh
565 sudo chmod u+x variable_child.sh
566 ./variable_parent.ssh
567 echo $ABC
568 source variable_parent.sh
569 echo $ABC
570 env
571 env | grep ABC=
572 history
Display a limited number of commands
If you want to display only the past four commands, run history 4
.
history 4
570 env
571 env | grep ABC=
572 history
573 history 4
Use grep to display certain commands
If you want to show only commands with certain strings, use the grep
command. For example, if you want to display sudo
commands only, run history | grep sudo
.
history | grep sudo
:
207 sudo chmod u+x test_child.sh
219 sudo chmod u+x variable_parent.sh
220 sudo chmod u+x variable_child.sh
: