History log file linux

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, . «

Читайте также:  X11 forwarding astra linux

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.

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 

Источник

bash shell output history file location

Where does the bash shell store the actual terminal session? I want to read the output of commands I used before. All I can find googling is how to store the output of a command. Since output is displayed on the screen, it has to be stored somewhere anyway. So my question is: where?

5 Answers 5

Bash only stores history of the commands you ran (which you can retrieve by typing history ). Unless you already have set the scroll-back to a very high number, there is no way to see the outputs that are older than the set value of scroll-back. Also setting this value to a very high number will make your scrolling sluggish since the lines are stored in the memory.

To store your future commands and their outputs, there are few options:

Using screen

Start a screen session by entering screen . Once you are inside screen, press Ctrl — a , then : , then enter log . All the I/O will be captured in screenlog files in the directory where you started the screen command.

Using script

You can start by typing script . A script session will start that will capture all the I/O to a file named typescript . You can exit the script session by Ctrl — d and view the logs in the typescript file.

tee is a handy tool. You can do something like this:

This will open a new bash shell inside the one you are already running. When you exit out of this, you can see the outputs in the file called log.txt

Читайте также:  Install postgresql on oracle linux

As Dustin Kirkland suggested in this post, you can also use byobu. Although, I have never used, terminal screencasting tools such as Shelr also sounds like an option.

Wow! Sorry for a non-constructive comment, but I have to say (write) it: this answer is just amazing.

There are lots of questions related to this one, but they all start with the (right) assumption that the output isn’t logged.

Nowhere: Bash’s (and any other shell that I know of’s) output isn’t logged.

Since output is displayed on the screen, it has to be stored somewhere anyway.

It is, but most likely not in plain text and not even on the disk (although this really is up to the terminal emulator): most likely, and at least in most cases, in a memory segment allocated by the terminal emulator.

However for sure it isn’t logged to a file, at least not by the shell, and I don’t know of terminal emulators which log the output to a file by default.

Indeed this doesn’t mean it’s impossible to log the terminal output: first I’ll mention something that I think not many are aware of, since I’ve never saw anyone mentioning this at least here on Ask Ubuntu: Konsole allows to save the scrollback to a file (perhaps there are other terminal emulators that provide such a functionality, Konsole is just the only one I know of), although this is limited by Konsole’s scrollback size limit.

This is often not really useful though, and most likely you’ll want to look into «proper» solutions to log a whole session’s output to a file (How do I log all input and output in a terminal session? and Ron’s answer).

There is a command named as script , if not installed then apt-get install script would do it.

Then in terminal just type script.

and do what ever you want , after you are done just type exit and then there will be a file created at your current directory with all stdout and stdin information.

This has nothing to do with your shell ( bash ), it isn a feature of the terminal emulator you are using. It is stored in your terminal’s «scrollback buffer». I haven’t been able to find any clear explanations of where exactly this is stored, but personal experience has shown me that it is stored somewhere in /tmp .

As the answer of the question linked to above suggests, it is most likely stored in a nameless file. To see what I mean, open a new file with a text editor:

Write a line of text to the file and save it. Now, while that file is still open, open a terminal and delete it:

Читайте также:  Linux mint проверка памяти

Since you still have the file open in gedit , you can continue writing to it. You could even write several gigabytes of data into it, despite the fact that the file has been deleted. That’s because deleting a file simply removes the link pointing to its inode. If its file descriptor is held open by another program, data can be written to it, despitre the fact that there is no longer an actual link (file) corresponding to the file descriptor on the file system.

All this is to say that your terminal’s history is probably saved using a trick like that, somewhere in a deleted file in /tmp . What you probably actually want is to simply increase the scrollback buffer size of youre terminal emulator so you can just scroll up and see it. The details of how to do this depend ont he terminal emulator you are using. Most have a command line switch that lets yous et this and many also have a GUI way of setting it. For example, in gnome-terminal (the default on Ubuntu) it’s Edit -> Preferences -> Profiles — click on your profile —> Edit -> Scrolling -> Limit scrollback to NNN:

Источник

Where are ALL ubuntu logs/terminal history stored

In what folders are the logs and key histories stored so that I may make a script to purge them. Is there a specific folder for the hibernation partition or a file by which it keeps the RAM data on hibernate? Is someone wanted to get rid of all command history/program load history/program execution history, where would they go?

4 Answers 4

There are a lot of places where things get logged, and it will be very diffucult to be exhaustive, depending on what applications you use. That said, here are the main places I can think of:

  • most system logs go into /var/log
  • firefox stores your history, cookies, etc. in ~/.mozilla/firefox This can be purged from Firefox (shift+ctrl+suppr)
  • zeitgeist is an history daemon, that populates the dash recent history. It can be purged from the privacy settings
  • terminal command history is saved on a per-user basis in ~/.bash_history Deleting this file will remove this history.
  • gnome applications (gedit, nautilus, etc. ) store recently used files in ~/.local/share/recently-used.xbel This file can be deleted if needed.

These are the main places I can think of, but any application can log things in various places. so it really depends on what logs you want to remove.

As mentionned by MrVaykadji, BleachBit is a GPL software that automates such cleansing task, and let you delete «log files» for a wide variety of known softwares. You can also easily add new cleaners with simple xml files. Might be what you are (ware) looking for!

Источник

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