Take a look at my history logging functions and see if they could be adapted to your needs.
This is what a couple of typical lines from my log file might look like:
echo hello ### [email protected] Bash-4.0 /dev/pts/1 192.168.2.22 20100510 17:53 /home/user/test
cd .. ### [email protected] Bash-4.0 /dev/pts/1 192.168.2.22 20100510 17:53 /home/user/test -> /home/user
The first line above includes a command, a comment marker, the user/host, shell version, terminal device and IP, the date and time and the directory that was current when the command was issued. The second line is an example of an entry that is produced when a cd
command is used and the function's -t
option is active. It shows the previous and new working directories.
To set that up:
Choose appropriate locations for files and add the steps above to your ~/.bashrc
files.
The function takes several optional switches. One of interest may be -l
. With it, commands are written to a log file. You can grep
that file and copy and paste commands that you need to re-run. If you omit that switch, the annotated lines are instead written to the shell's history where they can be recalled and reused using the history manipulation features of Bash. The fact that the annotations follow a comment character means that you can re-use the commands as-is and the annotations will be ignored.