Harvesting my tcsh command line .history

I am upgrading my first server today and I have an 209K .history file.
It has a lot of mumbo jumbo ((#+1501252163)time-date stamps?)) in addition to valuable commands.
How can I utilize these? Strip out the noise, clear dupes and categorized by initial command. Perhaps a nice list.
Is there a port for this?

I know am asking for alot, but I can't be the only one out there reusing my commands.
Do the optional shells use a .history file as well or different layout?
 
I just found the builtin command history. With the -h option I can get a good start.

history -h | sort > backup.history
 
history -h | sort > backup.history

You can add the -u flag to sort and "clear dupes," as you put it. Since your history has timestamps, you won't find any exact duplications, though, so you might be better off piping sort's output into uniq -f 1 or uniq -s 12. I don't use tcsh, so can't try them out myself.

After that I would use the *nix Swiss Army Knife, vim, to delete lines like :g/^#+\d\{-}\s\{}ls /d, etc.
 
That -u brought me down to 43K. Getting usable. Already scraping out my Nanobsd commands on my new box.
sh nanobsd.sh -wc ./apu2ap/apu2ap.conf
 
You might want to set this in your ~/.cshrc:
Code:
       histdup (+)
               Controls handling of duplicate entries in the history list.  If
               set to `all' only unique history events are entered in the
               history list.  If set to `prev' and the last history event is
               the same as the current command, then the current command is
               not entered in the history.  If set to `erase' and the same
               event is found in the history list, that old event gets erased
               and the current one gets inserted.  Note that the `prev' and
               `all' options renumber history events so there are no gaps.
You can also set how much history to save and how it should be saved:
Code:
        set history = 1000
        set savehist = (1000 merge)
 
I noticed that bash_history is used for that shell on FreeBSD. I guess every shell is different?

I think most shells have a similar idea, but implement it in their own ways. I use shells/zsh which creates a ~/.zsh_history file (although I've forced that in my ~/.zshrc file, so the default may be different).

Certainly shells/bash and shells/zsh allow you to configure history files so it can be as simple as a list of commands used, or include timestamps, it can be a hundred lines long or several thousand.
You'd need to check your shells documentation to figure out what you can and can't do :)
 
You can avoid duplicate lines in history by using this option in your bash.

export HISTCONTROL=ignoreboth:erasedups
 
Back
Top