Portál AbcLinuxu, 23. dubna 2024 05:21


Dotaz: Bash - konečné řešení vymazání historie

1.2.2015 18:18 RickettsialPox | skóre: 20 | Praha, Žižkov
Bash - konečné řešení vymazání historie
Přečteno: 854×
Odpovědět | Admin
Vím jak to funguje a proč se mi nedaří zbavit historie. Nepřijde mi však efektivní cpát 60 pokynů k vymazání souboru atp. Zaprvé - proč "history -c" nevymaže historii i z ostatních míst? No každopádně - nešlo by to nějak jednoduše mazat dočista? Totiž nechci nemít historii - ale jediné jednoduché řešení, kteréžto mne napadá, zní - po startu (profile) vymazat historii... Ovšem občas bych chtěl historii i v novém startu - zkrátka chtěl bych to řídit nějakým jedním jednoduchým příkazem. Tak mne napadlo, že si udělám proměnnou indikující, zda bylo vyžádáno mazání... No nějak takto bych to asi splácal. Jen než se do toho pustím - není něco hezčího? Mým hlavním problémem je, že používám virtuální terminály - z PCManFM. (Je to však vskutku pohodlné... :D)
Největší prvek každého hrdinského činu je strach. Život definuji jako "/dev/life >> /dev/null".

Řešení dotazu:


Nástroje: Začni sledovat (0) ?Zašle upozornění na váš email při vložení nového komentáře.

Odpovědi

1.2.2015 18:26 Kit
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Odpovědět | | Sbalit | Link | Blokovat | Admin
Zruš proměnnou HISTFILE.
1.2.2015 18:29 RickettsialPox | skóre: 20 | Praha, Žižkov
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Ale to bych právě nějak musel zadat v momentě vymazání a zase někdy vytvořit... :D (Jak píši - nechci být bez historie - chci jen řídit ručně vymazání. Teoreticky právě stačí "history -c", jenže ostatní aplikace to tam zase vrátí...)
Největší prvek každého hrdinského činu je strach. Život definuji jako "/dev/life >> /dev/null".
Řešení 1× (Erbureth)
1.2.2015 18:33 mhepp | skóre: 22
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Odpovědět | | Sbalit | Link | Blokovat | Admin
V příkazové řádce zadej*: man bash

pak napiš*: /HIST

A kochej se*:
...
      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
              current 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 HISTCON‐
              TROL.
       HISTFILE
              The  name  of  the  file  in  which  command  history  is  saved  (see HISTORY below).  The default value is
              ~/.bash_history.  If unset, the command history is not saved when a shell exits.
       HISTFILESIZE
              The maximum number of lines contained in the history file.  When this variable is assigned a value, the his‐
              tory  file  is  truncated, if necessary, to contain no more than that number of lines by removing the oldest
              entries.  The history file is also truncated to this size after writing it when a shell exits.  If the value
              is  0,  the  history  file  is truncated to zero size.  Non-numeric values and numeric values less than zero
              inhibit truncation.  The shell sets the default value to the value of HISTSIZE  after  reading  any  startup
              files.
       HISTIGNORE
              A  colon-separated  list of patterns used to decide which command lines should be saved on the history list.
              Each pattern is anchored at the beginning of the line and must match the complete line (no implicit  `*'  is
              appended).   Each  pattern is tested against the line after the checks specified by HISTCONTROL are applied.
              In addition to the normal shell pattern matching characters, `&' matches the previous history line.  `&' may
              be escaped using a backslash; the backslash is removed before attempting a match.  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 HISTIGNORE.
       HISTSIZE
              The  number of commands to remember in the command history (see HISTORY below).  If the value is 0, commands
              are not saved in the history list.  Numeric values less than zero result in every command being saved on the
              history list (there is no limit).  The shell sets the default value to 500 after reading any startup files.
       HISTTIMEFORMAT
              If this variable is set and not null, its value is used as a format string for strftime(3) to print the time
              stamp associated with each history entry displayed by the history builtin.  If this variable  is  set,  time
              stamps  are  written to the history file so they may be preserved across shell sessions.  This uses the his‐
              tory comment character to distinguish timestamps from other history lines.
...
*) Výsledek se může lišit
1.2.2015 18:38 RickettsialPox | skóre: 20 | Praha, Žižkov
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Jo počkat - já to pochopil blbě. Ono to jako má být tak, že se historie bude přesto ukládat? Jen se neuloží na konci? No a nemohu spíše smazat řádek, co to nastavuje? (Stejně bych to musel hodit někde do login akce, nebo tak.)
Největší prvek každého hrdinského činu je strach. Život definuji jako "/dev/life >> /dev/null".
1.2.2015 18:59 RickettsialPox | skóre: 20 | Praha, Žižkov
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Tak nějak mi to nefunguje - snad pomůže restart... (Neustále restartuji konzole jak pod rootem, tak pod normálním userem a pořád musím odnastavovat HISTFILE, poněvadž se vždy vymaže jen pro tu jednu konzoli a pak zase běží - rovněž přežívá i historie... :D)
Největší prvek každého hrdinského činu je strach. Život definuji jako "/dev/life >> /dev/null".
1.2.2015 19:17 nobody
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
# smaze historii nactenou v aktualni konzoli, na disku v ~/.bash_history ji ale nechava
history -c

# ulozi aktualni historii (po predchozim smazani tedy prazdnou) na disk do ~/.bash_history
history -w

# napoveda pro history, ktera je soucast bash a proto nelze zobrazit pres 'history --help'
help history
1.2.2015 19:20 RickettsialPox | skóre: 20 | Praha, Žižkov
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Funguje - děkuji.
Největší prvek každého hrdinského činu je strach. Život definuji jako "/dev/life >> /dev/null".
1.2.2015 19:39 Kit
Rozbalit Rozbalit vše Re: Bash - konečné řešení vymazání historie
Však si to zrušení HISTFILE zapiš do ~/.bashrc

Založit nové vláknoNahoru

Tiskni Sdílej: Linkuj Jaggni to Vybrali.sme.sk Google Del.icio.us Facebook

ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.