Saturday, 11 July 2009

bash-history - a tip and some thoughts.

A great tip on the Ubuntu-uk podcast this week for keeping your .bash_history file a little leaner (AND MORE SECURE!).

what's the difference between these two lines?

~mysqldump -u user -ppassword mydatabase > backup.sql
~ mysqldump -u user -ppassword mydatabase > backup.sql

well both do the same thing (backup a mysql database to a flat file).
However, the first variant would go into your .bash_history, whereas the second one wouldn't thanks to the space at the line start.

why does this matter?
1. you probably don't want to put plain text passwords into the shell history. It may be convenient, but this file is one of the first places anyone malicious (or simply mischievous) would look to harvest such things if they got physical or virtual access to your machine.

2. perhaps, like me, your .bash_history get's full of stuff like

cd ~
ls
cp -av /home/neil/bashpodder/2009-06-25/ .
mount /dev/sdb /media/player
sudo mount /dev/sdb /media/player
sudo -s
ssh -p 3298 -N -L 2948:192.168.88.2:3306 dentists@mywork.com
sudo umount /media/player
python
echo "http://feeds.conversationsnetwork.org/channel/itc" >> bashpodder/bp.conf
cd ~/windows_openmolar/openmolar/ && bzr pull

now of those commands, only one or two benefit from being available via arrow navigation. in future, I will be considering putting a space before the majority of my command line playing.

but d'you know what? I think I need to look into the behaviour of bash_history some more. Ideally I would like it to have everything from that terminal session directly available, spaces or no...(in case of typos, which I'll admit happen occasionally) but archive only those without.

I'll bet there's something in the man page... must check sometime.
Neil.

3 comments:

mnpbds said...

I find history to be very useful. Usually you get a list of commands such as:
363 lynx
364 history
365 ssh -l mpreston truth.positiveinternet.com
366 ssh -l eldc truth.positive-internet.com
367 sudo find / -type f -name "*" -exec grep "dental nurses" {} \; -print

To execute a command again a quick way is to type ! followed by the command number, so in the list above !365 would start a ssh login. Command 367 is a very useful one to find any file with the text "dental nurses". Regards, Mark

Neil said...

Thanks Mark,

3 really useful tips there.

all the more reason for me to keep my history clean though. If commands 1-400 are all "ls"...

DocBoy said...

iam a new user of openmolar. Thanks for your open source software. I would like to know if I can save patients file into external hardisk? I am planning upgrade to linuxmint11 from linuxmint9.