Archive

Posts Tagged ‘log’

Linux Bash: log commands of all shells immediately to a single command history

April 8, 2014 1 comment

One of the useful features of Linux Bash is to search the command history. For interactive search press Ctrl+R, start typing your command and the last executed command matching it will pop up (you can cycle through multiple commands that match your typing pressing Ctrl+R again). Although the feature is useful we like to tune it’s default config a bit in order to improve user experience. In the default config the history somehow depends on a) the shell instance you are using (this makes a difference if you use multiple shells at the same time), and b) commands do not get logged immediately to the history. We like to have a command typed in one shell available in the history of all shells immediately.

1. Append all shell commands of all shell to the history (already part of many newer distro releases including Ubuntu 14.04)
Append the following line to your ~/.bashrc file:

shopt -s histappend

2. Append all shell commands to the history immediately
Append the following line to your ~/.bashrc file:

PROMPT_COMMAND="history -a;$PROMPT_COMMAND" 

Each Bash opened after these changes will log all commands for all shell instances immediately.

Thx to darksider15 for having the original idea a long time ago.

Linux: remove files that got deleted while written – or how to lose track of files eating up your disk space

Just stumbled across why you should not simply delete files such as:

/var/log/syslog
/var/log/kern.log

These files get written permanently, therefore are opened. The application writing to the file has an according file handle, therefore deleting the file using

rm /var/log/syslog
rm /var/log/kern.log

deletes the representation of the data in the file system, not the data itself. As the file handle used by the application writing to these files uses the inode, not the file name, the file continues to exist. Therefore you do not free disk space – but lose track of the files eating up your space, if you don’t recognize the mistake. To recreate the access to the file via the file system simply recreate the files and restore their ownership:

touch /var/log/syslog
chown syslog:adm /var/log/syslog
touch /var/log/kern.log
chown syslog:adm /var/log/kern.log

You should see the files in the file system again then. If they stay empty (and you did not free any disk size), try:

reload rsyslog

Then you should see the log growing again – and your disk will finally be less occupied.

Categories: Linux Tags: , , , , ,