Uruchom polecenie w trybie bash bez zapisywania w historii

Odpowiedzi:

54

Dodaj spację przed poleceniem. polecenia zaczynające się od spacji nie umieszczają w historii:

root@ubuntu-1010-server-01:~# echo foo
foo
root@ubuntu-1010-server-01:~# history 
    1  echo foo
    2  history 
root@ubuntu-1010-server-01:~#  echo bar
bar
root@ubuntu-1010-server-01:~# history 
    1  echo foo
    2  history 

uderzenie człowieka

  HISTCONTROL
         A  colon-separated  list of values controlling how commands are
         saved on the history list.  If  the  list  of  values  includes
         ignorespace,  lines  which begin with a space character are not
         saved in the history list.  A value of ignoredups causes  lines
         matching  the  previous history entry to not be saved.  A value
         of ignoreboth is shorthand for ignorespace and  ignoredups.   A
         value  of erasedups causes all previous lines matching the cur
         rent line to be removed from the history list before that  line
         is  saved.   Any  value  not  in the above list is ignored.  If
         HISTCONTROL is unset, or does not include a  valid  value,  all
         lines  read  by the shell parser are saved on the history list,
         subject to the value of HISTIGNORE.  The second and  subsequent
         lines  of a multi-line compound command are not tested, and are
         added to the history regardless of the value of HISTCONTROL.
ooshro
źródło
1
Lepsza byłaby moja odpowiedź na $ HISTIGNORE. +1
Matt Simmons
1
uczyć się czegoś nowego każdego dnia.
David Rickman
1
Zwykle ustawiam to /etc/profilejako HISTCONTROL=ignorebothi eksportuję zmienną HISTCONTROL.
ewwhite
To chyba nie działa dla mnie? Wydaje się, że zapisuje się w historii, ale zawiera tylko przestrzeń z przodu. 486 echo test 487 historia 488 echo testspace 489 historia
Peter
Zignoruj ​​ten ostatni komentarz, wygląda na to, że działa w Ubuntu, ale nie w Debianie / innych systemach operacyjnych.
Peter
3

Warto również wspomnieć o sztuczce polegającej na zabiciu bieżącej sesji logowania zamiast normalnego wyjścia (co nie daje szansy na zapisanie historii). Jest to szczególnie przydatne, gdy logujesz się do udostępnionego klimatyzatora, zamiast pamiętać o prefiksie ze spacją, możesz po prostu zakończyć sesję, zabijając go. Najprostszym sposobem na zabicie jest uruchomienie tego polecenia:

kill -9 0

Pid 0 zawsze odnosi się do PID bieżącego procesu, więc w zasadzie wysyłasz do siebie śmiertelny sygnał zabicia. Często też tego używam zamiast normalnie wychodzić, ponieważ często zawieszam sesje przy normalnym wyjściu, prawdopodobnie z powodu jakiejś błędnej konfiguracji.

haridsv
źródło
1

Innym rozwiązaniem jest ustawienie pliku historii na katalog:

export HISTFILE=/
Perleone
źródło