GNU/Linux >> Tutoriels Linux >  >> Linux

En utilisant l'historique bash pour obtenir une commande précédente, copiez-la, puis "exécutez-la", mais avec la commande commentée

Je suggérerais qu'au lieu d'utiliser la commande history, vous utilisiez ctrl+r et commencez à taper cette commande. Lorsque vous appuyez sur une touche fléchée comme pour aller la modifier, elle sortira de la reconnaissance de saisie semi-automatique et vous permettra de la modifier avant de l'exécuter.

MISE À JOUR :également, si vous souhaitez parcourir les différentes commandes contenant la chaîne que vous venez de saisir, continuez à appuyer sur ctrl+r


En fait, vous pouvez simplement ajouter :p à la commande pour l'imprimer sans l'exécuter réellement. Par exemple :

$ ls -la
$ !!:p

Imprimera ls -la comme la commande précédente sans l'exécuter, et vous pouvez simplement appuyer sur (vers le haut) pour le trouver et le modifier.

Vous pouvez également faire

!123:p

pour imprimer la 123ème commande comme votre commande précédente.


Vous pouvez également essayer fc commande pour modifier la commande dans l'historique.

WIKI dit,

​fc​ est un programme standard sous Unix qui répertorie ou édite et réexécute les commandes saisies précédemment dans un shell interactif. fc est un intégré commande dans le bash coquille; aide fc affichera les informations d'utilisation.

En dehors de la recherche incrémentielle inversée (Ctrl +R ), nous avons encore plus de bash raccourcis :

À partir de man bash :

previous-history (C-p)
    Fetch the previous command from the history list, moving back in the list. 
next-history (C-n)
    Fetch the next command from the history list, moving forward in the list. 
beginning-of-history (M-<)
    Move to the first line in the history. 
end-of-history (M->)
    Move to the end of the input history, i.e., the line currently being entered. 
reverse-search-history (C-r)
    Search backward starting at the current line and moving 'up' through the history as necessary. This is an incremental search. 
forward-search-history (C-s)
    Search forward starting at the current line and moving 'down' through the history as necessary. This is an incremental search. 
non-incremental-reverse-search-history (M-p)
    Search backward through the history starting at the current line using a non-incremental search for a string supplied by the user. 
non-incremental-forward-search-history (M-n)
    Search forward through the history using a non-incremental search for a string supplied by the user.
yank-nth-arg (M-C-y)
    Insert the first argument to the previous command (usually the second word on the previous line) at point. With an argument n, insert the nth word from the previous command (the words in the previous command begin with word 0). A negative argument inserts the nth word from the end of the previous command. Once the argument n is computed, the argument is extracted as if the "!n" history expansion had been specified.
yank-last-arg (M-., M-_)
    Insert the last argument to the previous command (the last word of the previous history entry). With an argument, behave exactly like yank-nth-arg. Successive calls to yank-last-arg move back through the history list, inserting the last argument of each line in turn. The history expansion facilities are used to extract the last argument, as if the "!$" history expansion had been specified. 
shell-expand-line (M-C-e)
    Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions. See HISTORY EXPANSION below for a description of history expansion. 
history-expand-line (M-^)
    Perform history expansion on the current line. See HISTORY EXPANSION below for a description of history expansion.
insert-last-argument (M-., M-_)
    A synonym for yank-last-arg. 
operate-and-get-next (C-o)
    Accept the current line for execution and fetch the next line relative to the current line from the history for editing. Any argument is ignored. 
edit-and-execute-command (C-xC-e)
    Invoke an editor on the current command line, and execute the result as shell commands.

Linux
  1. Soyez trié avec sort en ligne de commande

  2. CentOS / RHEL :Comment obtenir la date et l'heure de la commande exécutée dans la sortie de la commande d'historique

  3. Réexécutez la commande précédente avec des arguments différents

  4. Comment obtenir uniquement l'utilisateur, le pid et la commande exécutée pour un processus spécifique ? (Ubuntu 11.10)

  5. Exécuter la commande dans bash sans enregistrer dans l'historique

Regardez les commandes et les tâches avec la commande Linux watch

Importer des fonctions et des variables dans Bash avec la commande source

Utilisation de modificateurs de mots avec l'historique Bash sous Linux

Avec Bash après avoir "fait défiler" jusqu'à une commande précédente… Comment passer ensuite à la suivante dans cette histoire ?

Obtenir tous les fichiers sauf les fichiers du tableau - Bash ?

Copier des fichiers en toute sécurité avec la commande SCP