How to display Command History in Linux | history Command

Configurare noua (How To)

Situatie

he command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history.

Solutie

Pasi de urmat
history

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.

Display a Limited Number of Commands History

To show the limited number of commands that executed previously as follows:

history 5 

Lightbox

Execute a command using its event number with the ! symbol. For instance:

!1997 
This will rerun the command with event number 1997.

To print a command before executing it to avoid errors, use the :p option after the event number. Example:

!1997:p
This will display the command associated with event number 1997 without executing it

Search Command History with grep

Combine the history command with grep for efficient searching. Example:

Example:

history | grep chpasswd 

Lightbox

Tip solutie

Permanent

Voteaza

(5 din 10 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?