{"id":2151,"date":"2021-02-25T08:38:43","date_gmt":"2021-02-25T08:38:43","guid":{"rendered":"https:\/\/swiv.com.br\/linux-histfile\/"},"modified":"2026-05-27T20:02:52","modified_gmt":"2026-05-27T19:02:52","slug":"linux-histfile","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/02\/25\/linux-histfile\/","title":{"rendered":"Linux HISTFILE"},"content":{"rendered":"\n<p>Os comandos executados no Linux ficam armazenados em um arquivo de hist\u00f3rico, que facilita o reaproveitamento desses comandos, ou nos permite analisar o que foi feito recentemente em um ambiente.<\/p>\n\n\n\n<p>Executando o comando history:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;root@oel7 ~]# history\n    1  ifconfig -a\n    2  reboot\n    3  df -h\n    4  exit\n    5  cd \/\n    6  ll\n    7  cd BINARIO\/\n    8  ll\n    9  cd install\/response\/\n   10  ll\n   11  cat db_install.rsp\n   12  cat \/etc\/shells\n   13  echo $SHELL\n   14  type echo\n   15  echo $VARIAVEL2\n   16  exit\n   17  echo $VARIAVEL2\n   18  exit\n   19  cd\n   20  ll\n   21  .\/variavel.sh\n   22  exit\n   23  history\n&#x5B;root@oel7 ~]#\n<\/pre><\/div>\n\n\n<p>Cada usu\u00e1rio ter\u00e1 seu pr\u00f3prio hist\u00f3rico, que \u00e9 lido do arquivo HISTFILE, que pode ser encontrado como abaixo (neste exemplo, \u00e9 poss\u00edvel tamb\u00e9m ver o tamanho m\u00e1ximo deste hist\u00f3rico):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;root@oel7 ~]# set | grep HISTFILE\nHISTFILE=\/root\/.bash_history\nHISTFILESIZE=1000\n<\/pre><\/div>\n\n\n<p>Ao disparar o comando &#8220;!!&#8221;, ser\u00e1 executado o \u00faltimo comando do history:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;root@oel7 ~]# !!\nset | grep HISTFILE\nHISTFILE=\/root\/.bash_history\nHISTFILESIZE=1000\n<\/pre><\/div>\n\n\n<p>Podemos tamb\u00e9m executar um comando espec\u00edfico, atrav\u00e9s do seu n\u00famero associado, conforme abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;root@oel7 ~]# history\n    1  ifconfig -a\n    2  reboot\n    3  df -h\n    4  exit\n    5  cd \/\n    6  ll\n    7  cd BINARIO\/\n    8  ll\n    9  cd install\/response\/\n   10  ll\n   11  cat db_install.rsp\n   12  cat \/etc\/shells\n   13  echo $SHELL\n   14  type echo\n   15  echo $VARIAVEL2\n   16  exit\n   17  echo $VARIAVEL2\n   18  exit\n   19  cd\n   20  ll\n   21  .\/variavel.sh\n   22  exit\n   23  history\n   24  set | grep HISTFILE\n   25  history\n   26  set | grep HISTFILE\n   27  history\n   28  date\n&#x5B;root@oel7 ~]# !28\ndate\nThu Feb 25 05:27:43 -03 2021\n<\/pre><\/div>\n\n\n<p>Podemos usar o &#8220;!&#8221; seguido de uma string, que executar\u00e1 o \u00faltimo comando identificado no hist\u00f3rico que contenha a string informada:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;root@oel7 ~]# ls \/tmp\/\nssh-X1jOYJWdabZs\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-bolt.service-r89566\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-colord.service-DUc5fq\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-cups.service-C1I5d9\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-fwupd.service-575LFE\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-rtkit-daemon.service-OZRWWP\ntracker-extract-files.0\n&#x5B;root@oel7 ~]# !ls\nls \/tmp\/\nssh-X1jOYJWdabZs\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-bolt.service-r89566\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-colord.service-DUc5fq\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-cups.service-C1I5d9\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-fwupd.service-575LFE\nsystemd-private-cb5ebc685110472aba9ff1ca691f8363-rtkit-daemon.service-OZRWWP\ntracker-extract-files.0\n&#x5B;root@oel7 ~]#\n<\/pre><\/div>\n\n\n<p>Para limpar o hist\u00f3rico, basta emitir o comando abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;root@oel7 ~]# history -c\n&#x5B;root@oel7 ~]# history\n    1  history\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Os comandos executados no Linux ficam armazenados em um arquivo de hist\u00f3rico, que facilita o reaproveitamento desses comandos, ou nos permite analisar o que foi feito recentemente em um ambiente. Executando o comando history: Cada usu\u00e1rio ter\u00e1 seu pr\u00f3prio hist\u00f3rico, que \u00e9 lido do arquivo HISTFILE, que pode ser encontrado como abaixo (neste exemplo, \u00e9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-2151","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/2151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=2151"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/2151\/revisions"}],"predecessor-version":[{"id":9259,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/2151\/revisions\/9259"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=2151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=2151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=2151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}