Let's understand the Linux history command. How and when can we use it?
# Linux history command how to use
The "history" command in Linux is one of the most commonly used commands. When you type "history," it displays a list of recently used commands along with their corresponding numbers
177 git status
178 git pull
179 cd ~/.ssh
You can easily check the previously entered command line history as shown above.! Learn about available options for history
The "history" command can have several useful options set. By default, history will display the last 500 (or 1000) entries entered. Here are some frequently used options:1. If you want to view by page:
- Starting from the first page, press the space bar to move one page at a time.
history | less2. If you want to see only the last 10 commands
- Simply output the recent 10 commands.
hisotry | tail3. If you want to show only a certain number of items
- The following displays the last 5, 15, and 25 items respectively.
history 54. Using grep with history
- This command is commonly used with pipelines and the grep format. For example, to only view a list containing "git", one can input the command as follows:
history | grep gitAdditional) Using pipelines consecutively.
You can use pipelines consecutively as shown below. If you use the keywords and tail simultaneously, it will be as follows.
history | grep git | tail
You can find commands using git, but you can only see the latest 10.! Other useful history tips and information
Here are some tips or information that can be useful when used or utilized together.1. How to run the desired line again.
When using history, using the exclamation mark symbol allows the user to execute that command again, which is very convenient. For example, to execute the 100th line again, use it as follows.
!1002. Show and output the last command.
This is a way to execute the last command by showing it again. It uses two exclamation marks (!!).
!!3. If you want to see the command again, print it.
If you want to output the 100th command, use "p".
!100:p! Delete the history of history.
The following is the command to delete the history contents.1. If you only want to delete one, use the option -d.
history -d 1002. To delete everything, use the -c option.
// 100번째 history만 삭제됨
To delete all the contents of the history, follow the steps below.
// 모든 history 내용을 삭제
We have briefly looked at the Linux history command up to this point.