CheatSheet: Bash history
Erreur lors de la création de la vignette : Fichier manquant | Aide-Mémoire Cette page est juste un aide-mémoire et non une documentation complète. |
Le point d'exclamation[modifier | modifier le wikicode]
Ce petit caractère peut vite devenir un puissant allié comme il permet de rapidement interagir avec l'historique.
Relancer une commande[modifier | modifier le wikicode]
Combien de fois avez-vous oublié de taper sudo ... Alors on remonte, on va au début de la ligne, on ajoute le "sudo " ... Et si on a un soucis (un insert activé, un caractère invisible ...) on recommence encore ...
Alors qu'il suffirait de simplement taper quelques caractères ...
[user@linux] $ | sudo !! | dblclick to copy |
Et si c'est pas la dernière commande il suffit de remplacer le deuxième !
- On peut mettre soit un chiffre négatif: on veut X commande en arrière
- Soit un positif: on veut la commande X de l'historique
- Soit carrément saisir le début de la commande
Les modificateurs[modifier | modifier le wikicode]
La documentation GNU :
Contenu étendu |
---|
9.3.3 Modifiers After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a ‘:’. These modify, or edit, the word or words selected from the history event. h Remove a trailing pathname component, leaving only the head. t Remove all leading pathname components, leaving the tail. r Remove a trailing suffix of the form ‘.suffix’, leaving the basename. e Remove all but the trailing suffix. p Print the new command but do not execute it. q Quote the substituted words, escaping further substitutions. x Quote the substituted words as with ‘q’, but break into words at spaces, tabs, and newlines. The ‘q’ and ‘x’ modifiers are mutually exclusive; the last one supplied is used. s/old/new/ Substitute new for the first occurrence of old in the event line. Any character may be used as the delimiter in place of ‘/’. The delimiter may be quoted in old and new with a single backslash. If ‘&’ appears in new, it is replaced by old. A single backslash will quote the ‘&’. If old is null, it is set to the last old substituted, or, if no previous history substitutions took place, the last string in a !?string[?] search. If new is is null, each matching old is deleted. The final delimiter is optional if it is the last character on the input line. & Repeat the previous substitution. g a Cause changes to be applied over the entire event line. Used in conjunction with ‘s’, as in gs/old/new/, or with ‘&’. G Apply the following ‘s’ or ‘&’ modifier once to each word in the event. Source: https://www.gnu.org/software/bash/manual/html_node/Modifiers.html |