Outils pour utilisateurs

Outils du site


issue102:encart

Ceci est une ancienne révision du document !


Using BASH command history by Jeremy Boden Would you like the command entry screen to be a bit less work to use? Instead of repetitive typing of commands, access to previously entered commands can be a big help. This feature works either in a “real” command entry screen (accessed via one of the CTRL+ALT+F1 thru CTRL+ALT+F6 shortcuts) or perhaps more commonly, via the Terminal window option. It turns out that a command entry screen keeps a copy of (typically) the last 500 commands entered. One option would be to enter the history command (without any parameters), I (currently) see a long list:­ [493 lines omitted] 494 locate amstex.sty 495 cd … 500 sudo apt­get clean 501 sudo du ­h /backup | sort ­k 2 502 history

Utiliser la commande BASH history Par Jeremy Boden

Voudriez-vous que que l'écran de saisie de commande soit un peu moins fastidieux à utiliser ? Au lieu de répéter la saisie des commandes, l'accès aux commandes entrées précédemment peut vous être d'une grande aide. Cette focntionnalité marche, soit dans un des écrans d'entrée de commande « réels » (accessibles via un des raccourcis CTRL+ALT+F1 à CTRL+ALT+F6), soit, et peut-être plus communément, par l'option de la fenêtre de Terminal.

Il se trouve qu'un écran d'entrée de commande garde une copie de (typiquement) les 500 dernières commandes entrées. Une option serait de saisir la commande history (sans aucun paramètre) ; je vois (actuuellement) une longue liste :

[493 lignes omises] 494 locate amstex.sty 495 cd … 500 sudo apt­get clean 501 sudo du ­h /backup | sort ­k 2 502 history

Note that the commands entered are listed in reverse order, so that the most recent command is shown last. Actually, the history command comes with a multitude of options – which I shan't discuss. Instead, we can access the command history in a simple interactive way. It is a “well known fact” that pressing the up­arrow/down­arrow keys will scroll through your command history; in particular the up­arrow will display the previous command in a command screen, clearly you will want to avoid pressing this key too many times! So we search our history using “reverse intelligent search”. My command screen is waiting for me to enter a command, so it reads:­ jeremy@hector:~$ Pressing CTRL+R, will cause this to change to:­ (reverse­i­search)`': I entered mlo – (I was expecting to type mlocate) and my screen changed to:­ (reverse­i­search)`mlo': sudo /usr/bin/updatedb.mlocate

• Note that the search string is shown enclosed between a backtick character and a single quote and separated from the full command by a colon. I chose to run this command unchanged, by pressing the enter key. • If your search string includes spaces, enter the exact number of spaces required. • Note that in my search, it was only necessary to enter a few adjacent characters – it is not necessary to start from the beginning of the command. • It may happen that your search string matches a number of different commands – to access an older command, just press CTRL+R again. • To amend and run the retrieved command, press the left­arrow or right­arrow keys, type in the alterations and press enter to run the command. • At any point, prior to pressing the enter key, you can abandon running the command by pressing CTRL+C. After pressing enter (to run the command) or CTRL+C to cancel any command execution, your command entry screen will return to its original appearance.

issue102/encart.1447352548.txt.gz · Dernière modification : 2015/11/12 19:22 de d52fr