GNU/Linux >> Tutoriales Linux >  >> Linux

Usando el historial de bash para obtener un comando anterior, cópielo y luego 'ejecútelo' pero con el comando comentado

Sugeriría que en lugar de usar el comando de historial, use ctrl+r y comienza a escribir ese comando. Cuando presiona una tecla de flecha como si fuera a modificarla, dejará de reconocerse por completo automáticamente y le permitirá editar antes de ejecutarla.

ACTUALIZAR:también, si desea recorrer los diferentes comandos que contienen la cadena que acaba de escribir, siga presionando ctrl+r


En realidad, puedes agregar :p al comando para imprimirlo sin ejecutarlo realmente. Por ejemplo:

$ ls -la
$ !!:p

Imprimirá ls -la como el comando anterior sin ejecutarlo, y puede presionar (arriba) para encontrarlo y editarlo.

También puedes hacer

!123:p

para imprimir el comando 123 como su comando anterior.


También puedes probar fc comando para editar el comando en el historial.

WIKI dice,

​fc​ es un programa estándar en Unix que enumera o edita y vuelve a ejecutar comandos ingresados ​​previamente en un shell interactivo. fc es un incorporado comando en el bash caparazón; ayuda fc mostrará información de uso.

Aparte de la búsqueda incremental inversa (Ctrl +R ), tenemos más bash atajos:

Desde 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. Ordenarse con ordenar en la línea de comando

  2. Copie y pegue en la línea de comandos de Linux con xclip

  3. Consejos de Bash para el día a día en la línea de comandos

  4. Con Bash después de "desplazarse" hasta un comando anterior... ¿Cómo pasar al siguiente en este historial?

  5. Obtener todos los archivos excepto los archivos en matriz:¿Bash?

Copie archivos de forma segura con el comando SCP

CentOS/RHEL:cómo obtener la fecha y la hora del comando ejecutado en la salida del comando del historial

Usando el comando `fecha` para obtener el mes anterior, actual y el próximo

'&&' vs. '&' con el comando 'test' en Bash

Vuelva a ejecutar el comando anterior con diferentes argumentos

¿Cómo hacer que solo el usuario, el pid y el comando se ejecuten para un proceso específico? (Ubuntu 11.10)