GNU/Linux >> Znalost Linux >  >> Linux

Pomocí historie bash získáte předchozí příkaz, zkopírujte jej a poté jej „spusťte“, ale s komentářem příkazu

Navrhoval bych místo použití příkazu history použít ctrl+r a začněte psát tento příkaz. Když stisknete klávesu se šipkou, jako byste ji chtěli upravit, vypadne z rozpoznání automatického doplňování a umožní vám úpravy před spuštěním.

AKTUALIZACE:také, pokud chcete procházet různými příkazy, které obsahují řetězec, který jste právě napsali, stiskněte ctrl+r


Ve skutečnosti stačí připojit :p k příkazu, který jej vytiskne, aniž by jej skutečně spustil. Například:

$ ls -la
$ !!:p

Vytiskne ls -la jako předchozí příkaz bez jeho spuštění a stačí stisknout (nahoru), abyste jej našli a upravili.

Můžete také

!123:p

vytiskněte 123. příkaz jako váš předchozí příkaz.


Můžete také zkusit fc příkaz pro úpravu příkazu v historii.

WIKI říká,

​fc​ je standardní program na Unixu, který vypisuje nebo upravuje a znovu provádí příkazy dříve zadané do interaktivního shellu. fc je vestavěný příkaz v bash skořápka; help fc zobrazí informace o použití.

Kromě obráceného inkrementálního vyhledávání (Ctrl +R ), máme další bash zkratky:

Od 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. Sledujte příkazy a úkoly pomocí příkazu watch v systému Linux

  2. Importujte funkce a proměnné do Bash pomocí příkazu source

  3. Seřadit pomocí řazení na příkazovém řádku

  1. Použití slovních modifikátorů s historií Bash v Linuxu

  2. Rozumíte vykřičníku (!) v Bash?

  3. Použití –exclude With The Du Command?

  1. Získat všechny soubory kromě souborů v poli – Bash?

  2. CentOS / RHEL :Jak získat datum a čas provedeného příkazu ve výstupu příkazu historie

  3. najít a zkopírovat soubor pomocí Bash