Raspberry Pi_Eng_10.1.4 Utilizing Command Execution History


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


10.1.4  Utilizing Command Execution History

 

When working at the Terminal, you may work a task repeatedly on multiple files, or work multiple tasks on a specific file. In addition, there are times when you need to reconfirm what tasks you have done previously in multiple steps. In some cases, you may want to correct partially and rework the command in case the input is wrong and an error occurs. When you execute various commands, it is useful to know the history of commands that you have executed before.

So, Linux manages the history of commands executed by a specific user since booting, and has a system that allows users to retrieve a list of past tasks one by one.

In the command execution history, only the command itself is recorded, and the output of the execution result of the command is not stored. In addition, not only the normally executed command but also the erroneously executed command is saved.

 

10.1.4.1    Retrieving History by Arrow Keys

 

To confirm the history of the execution command, use the arrow keys as shown below:

    Up arrow key          -- Go to previous comman

    Down arrow key      -- Go to next command

 

The retrieved previous execution command is displayed at the position where the current command is input in the Terminal screen. The user can re-execute the command, or modify a part of the command and then execute it. If the retrieved command is not what you want, you can move to the previous command or the next command and search for the desired command.

 

[Used Example]

First, let's run the command in the following order.

 

pi@raspberrypi ~/testdata $ ls -l

total 20

-rw-r--r-- 1 pi pi   62 Apr 23 13:06 customer_list.txt

-rw-r--r-- 1 pi pi  123 Apr 23 13:00 customer_product.txt

drwxr-xr-x 4 pi pi 4096 Apr 25 07:56 TestFolder01

drwxr-xr-x 2 pi pi 4096 Apr 10 13:32 TestFolder02

-rw-rw---- 1 pi pi  113 Apr 23 08:22 user_guide01.txt

pi@raspberrypi ~/testdata $ mkdir TestFolder03

pi@raspberrypi ~/testdata $ echo 'Test Data' > TestFolder03/test.txt

pi@raspberrypi ~/testdata $ ls TestFolder03 -l

total 4

-rw-r--r-- 1 pi pi 10 Apr 25 07:59 test.txt

 

After the above command is executed in sequence, if you press the [Up arrow] button, the previous commands is displayed one by one. The following screen shows that the second previous command "echo 'Test Data'> TestFolder03/test.txt" is displayed by pressing the [Up arrow] button twice.

 


 

 


 

10.1.4.2    "history" Command

 

When you run the "history" command, you can see a list of all commands executed so far.

 

[Command Format]

history  [Event Designators]    [Word Designators]     [Modifiers]

 

[Command Overview]

   This shows a list of previously executed commands.

   User privilege          -- Normal user.

 

[Detail Description]

   None

 

[Main Option]

   Event Designators

!n    

Refer to command line n.

!-n

Refer to the current command minus n.

!!

Refer to the previous command. This is a synonym for `!-1'.

!string

Refer to the most recent command preceding the current position in the history list starting with string.

!?string[?]

Refer to the most recent command preceding the current position in the history list containing string.  The trailing ? may be omitted if string is followed immediately by a newline.

 

The following shows the result of executing the "history" command. You can notice that it shows the history list of all commands executed so far in order.

 

pi@raspberrypi ~/testdata $ history

ls l

mkdir TestFolder03

echo 'Test Data' > TestFolder03/test.txt

ls TestFolder03 -l