Kali linux bash history

Where is bash’s history stored?

If I run history , I can see my latest executed commands. But if I do tail -f $HISTFILE or tail -f ~/.bash_history , they do not get listed. Does the file get locked, is there a temporary location or something similar?

6 Answers 6

Bash maintains the list of commands internally in memory while it’s running. They are written into .bash_history on exit:

When an interactive shell exits, the last $HISTSIZE lines are copied from the history list to the file named by $HISTFILE

If you want to force the command history to be written out, you can use the history -a command, which will:

Append the new history lines (history lines entered since the beginning of the current Bash session) to the history file.

Write out the current history to the history file.

which may suit you more depending on exactly how you use your history.

If you want to make sure that they’re always written immediately, you can put that command into your PROMPT_COMMAND variable:

export PROMPT_COMMAND='history -a' 

Side note: if your .bash_history file accidentally becomes owned by root, things stop working. In that case, check the ownership and use sudo to fix the ownership if needed.

@young_souvlaki I expect your man history is for a library; at least, that’s what the only such man page I have available says at the top. It would be unusual for a library to document command-line options of other software, but help history (in Bash) will show applicable Bash documentation.

Thank you! You are correct! Oddly man history defaults to «history(n)» under «Tcl Built-In Commands». man 3 history gives the «Library Functions Manual». help history gives the options described.

(Not an answer but I cannot add comments)

If you are checking .bash_history because you just want delete a specific command (e.g. containing a password in clear), you can directly delete the entry in memory by history -d .

For example, supposing an output like:

$ history 926 ll 927 cd .. 928 export --password=super_secret 929 ll 

and you want purge the export line, you can simply achieve it by:

bash keeps it in working memory, bash can be configured to save it when bash closes or after each command, and to be loaded when bash starts or on request.

If you configure to save after each command, then consider the implications of having multiple bash running at same time. (command lines will be interleaved)

The start of you answer makes it sound as if the history is stored in a file called bash, or even in the bash exetable. I would write «It is stored by bash in memory, . «

While running, the history is kept only in memory (by default) if:

  • set -o history (an H in echo «$-» ) is set.
  • HISTSIZE is not 0 and
  • HISTIGNORE is not * (or some other very restrictive pattern).

If any of the above fail, no history is stored in memory and consequently no history could or will be written to disk.

History in memory is written to disk if:

But only when the shell exits or if the commands history -a (append) or history -w (write) are executed.

To trigger an immediate write to disk you can use the variable:

which will append the new history lines to the history file. These are history lines entered since the beginning of the current bash session, but not already appended to the history file.

Читайте также:  Посмотреть арп таблицу linux

To overwrite the history in the HISTFILE with the list from memory.

So, you can remove a command from the history in memory:

 $ history 5 6359 ls 6360 cd .. 6361 comand --private-password='^%^&$@#)!@*' 6362 top 6363 set +o | less $ history -d 6361 $ history 5 6359 ls 6360 cd .. 6361 top 6362 set +o | less $ history -w 

And write it to disk with the last command:

 history -w # with `shopt -u histappend` unset 

Источник

How to Use History command in Kali Linux Terminal

In Kali Linux, the “history” command allows you to access a numbered list of previously executed commands within the current Terminal session. By typing “history” in the Terminal, you can view the command history and scroll through it using the arrow keys. To execute a specific command, enter its corresponding number. Additionally, the “Ctrl+R” shortcut enables you to search for specific commands by typing related keywords. Using these features, you can conveniently revisit and re-execute commands from your history in the Kali Linux Terminal, but most new Kali users have questions about how to clear Kali Linux history in the terminal.

How to Use History command in Kali Linux Terminal

History command in Kali Linux Terminal:- Most of the time every Kali Linux user uses ↑ Upwards Arrow symbol and ↓ Arrow symbol for previous command but you can use History command see all previous command.

How to Use Kali Linux History Command

Command:- history ( GNU History Library )

If you want see terminal previous command history just type history.

┌──(kali㉿kali)-[~] └─$ history 1 history 2 gedit .zsh_history 3 history 4 clear 5 history . . 289 cal 290 clear 291 cal -y 292 clear 293 cal 1988 294 clear 

How to see and type previous command

┌──(kali㉿kali)-[~] └─$ !291 ┌──(kali㉿kali)-[~] └─$ cal -y 2021 January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 4 5 6 3 4 5 6 7 8 9 7 8 9 10 11 12 13 7 8 9 10 11 12 13 10 11 12 13 14 15 16 14 15 16 17 18 19 20 14 15 16 17 18 19 20 17 18 19 20 21 22 23 21 22 23 24 25 26 27 21 22 23 24 25 26 27 24 25 26 27 28 29 30 28 28 29 30 31 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 1 1 2 3 4 5 4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12 11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19 18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26 25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30 30 31 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 1 2 3 4 5 6 7 1 2 3 4 4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11 11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18 18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25 25 26 27 28 29 30 31 29 30 31 26 27 28 29 30 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 4 3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11 10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18 17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25 24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31 31 

How to run previous command fast shortcut key

┌──(kali㉿kali)-[~] └─$ !! ┌──(kali㉿kali)-[~] └─$ cal -y 2021 January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 4 5 6 3 4 5 6 7 8 9 7 8 9 10 11 12 13 7 8 9 10 11 12 13 10 11 12 13 14 15 16 14 15 16 17 18 19 20 14 15 16 17 18 19 20 17 18 19 20 21 22 23 21 22 23 24 25 26 27 21 22 23 24 25 26 27 24 25 26 27 28 29 30 28 28 29 30 31 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 1 1 2 3 4 5 4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12 11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19 18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26 25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30 30 31 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 1 2 3 4 5 6 7 1 2 3 4 4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11 11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18 18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25 25 26 27 28 29 30 31 29 30 31 26 27 28 29 30 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 4 3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11 10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18 17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25 24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31 31 

How To Remove Or Delete Kali Linux Terminal Command History

Any other Linux operating system you need to just enter history -d to delete all history or history -d for the particular command to clear the contents of the history file and then use history -c execution or save changes.

Читайте также:  Установить firefox esr linux

But Kali Linux this command nor executable you need to delete manually see below command.

Find this .zsh_history file and open any text editor just clear all text and save then close terminal

kali linux history command

You need to just type below command

┌──(kali㉿kali)-[~] └─$ mousepad .zsh_history 

Now history file open, then do whatever you want.

This is the best method you can remove or delete Kali Linux command history.

Conclusion

  • Open the Terminal.
  • Type “history” and press Enter.
  • The Terminal will show a list of previously executed commands.
  • Use the arrow keys to scroll through the list.
  • To execute a command from history, type the command number and press Enter.
  • Use “Ctrl+R” to search for specific commands by typing keywords.

As per your request, we write this article if you have any other requests please visit our YouTube channel:- https://youtube.com/@amolblog.

Other Articles for you:

Источник

Где хранится история ввода команд?

Всех с наступающим!
Куда в Кали сохраняется история ввода команд помимо файла zsh_history?
Команда history – показывает всю историю, а zsh_history хранит только часть..

Простой 3 комментария

Lynn

SHA_bash

Lynn «Кофеман», в Кали по дефолту стоит zhs. Но не вся история команд сохраняется в zsh_history почему-то. (Команды из под root не беру в счёт)

SHA_bash

Финский Мачо, нет. Команды под юзером и под рутом исполняются в zsh (проверял), ну и само собой сохраняются в разные файлы истории

Denkuwus

В Kali Linux история ввода команд обычно сохраняется в файле ~/.bash_history для оболочки Bash и в файле ~/.zsh_history для оболочки Zsh.

По умолчанию оболочка Bash сохраняет историю ввода команд при выходе из оболочки и загружает историю при запуске нового сеанса оболочки. Размер файла истории определяется значением переменной среды HISTSIZE. Вы можете изменить это значение, добавив следующую строку в файл ~/.bashrc:

Читайте также:  Удаление маршрута route linux

Это установит размер файла истории на 1000 команд. Вы также можете изменить переменную HISTFILESIZE, чтобы изменить максимальный размер файла истории.

Файл ~/.zsh_history работает аналогичным образом для оболочки Zsh. Вы можете изменить размер файла истории, задав переменные HISTSIZE и SAVEHIST в файле ~/.zshrc. Например:

HISTSIZE=1000 SAVEHIST=1000

Это установит размер файла истории на 1000 команд и сохранит историю при выходе из оболочки.

SHA_bash

Это прекрасно, но где расположен файл с историей (с которым работает команда history)?
.zsh_history я – нашёл, а .bash_history – нет!

Denkuwus

SHA_bash, Этот файл находится в вашем домашнем каталоге и используется командой history для отображения списка команд, которые вы вводили в прошлом.

Вы можете просмотреть содержимое файла .bash_history, выполнив следующую команду:

Это отобразит содержимое файла .bash_history в терминале. Вы также можете использовать команду history для отображения списка команд, которые вы ввели в прошлом. Например:

Это отобразит список команд, которые вы ввели, вместе с номером команды и временем, когда команда была введена. Затем вы можете использовать номер команды для быстрого доступа к ранее введенной команде. Например, чтобы выполнить команду с номером команды n, вы можете использовать нотацию !n, например:

Это выполнит команду с номером команды n.

SHA_bash

Denkuwus, я посмотрел в домашней директории через ls -a, но не нашёл среди всего bash_history..

И почему-то команда history не работает с ключом , чтобы очистить историю..

Denkuwus

SHA_bash, Возможно, файл .bash_history не создается или по какой-то причине удаляется.

По умолчанию оболочка bash должна создать файл .bash_history в вашем домашнем каталоге и сохранить запись введенных вами команд. Если файл .bash_history не создается или удаляется, вам может потребоваться проверить конфигурацию bash, чтобы увидеть, есть ли какие-либо настройки, вызывающие такое поведение.

Чтобы проверить конфигурацию bash, вы можете просмотреть файл ~/.bashrc в своем домашнем каталоге. Этот файл содержит набор команд и настроек, которые выполняются каждый раз, когда вы запускаете новую оболочку bash. Вы можете найти любые настройки, которые могут повлиять на создание или удаление файла .bash_history.

Что касается команды history, то для очистки файла истории используется параметр -c. Если вы не можете использовать параметр -c для очистки истории, это может быть связано с тем, что файл .bash_history не существует или у вас нет разрешения на изменение файла.

Вы можете проверить права доступа к файлу .bash_history, выполнив команду ls -l ~/.bash_history. Это покажет вам разрешения на файл .bash_history и владельца файла. Если у вас нет прав на запись в файл, вы не сможете его изменить.

Если вы не можете найти файл .bash_history или у вас нет разрешения на его изменение, вам может потребоваться обратиться к системному администратору или проверить документацию для вашей версии bash, чтобы узнать, есть ли какие-либо другие варианты очистки истории. .

Источник

Оцените статью
Adblock
detector