4

I store my commandline history in TCSH, but I want to prevent certain frequent, simple commands like "exit", "cd" to be included in the history (the history holds only a fixed number of commands, so I want to retain only the useful commands).

Is there a way to specify an "exclusion list" - a list that will contain commands that would not be added in the current history file ? That way, I can keep only the most relevant commands in history and filter out the ones I don't want to clog the history.

4
  • It would be nice if people would comment on why this needs to be closed !! I see 2 close votes in 5 minutes, but not a single clarification why !!
    – TCSGrad
    May 22, 2011 at 4:47
  • 1
    Not programming.
    – nobody
    May 22, 2011 at 4:54
  • @Andrew - From the one response I've got so far, it seems the answer is to "pro grammatically filter the history right before quitting" - in which case, does it not fall in the realm of stackoverflow ???
    – TCSGrad
    May 22, 2011 at 5:28
  • (Migrated from Super User at original asker's request. Originally asked on Stack Overflow.)
    – nhinkle
    May 22, 2011 at 6:53

3 Answers 3

5

It's not exactly what you want, but this may help:

  histdup (+)
    Controls handling of duplicate entries in the history list.  If set to `all' only unique his-
    tory  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.

So you put a 'set histdup = all' in your .tcshrc, and while you will still get trivial commands in your history, you will only get one instance of each, which at least reduces the clutter.

3

If you mean something like the variables in bash, HISTCONTROL and HISTIGNORE, where

HISTCONTROL=ignorespace does not load into your history any command preceded by a space and

HISTIGNORE=ls:cd:exit prevents all the listed commands being added to your history, then no - that functionality is not natively in tcsh.

5
  • Really ?? Wow - thats a pretty big drawback to tcsh IMHO...Any ideas as how one might work around that ?
    – TCSGrad
    May 22, 2011 at 11:41
  • @shan23: tcsh is an old shell that hasn't seen much development in a while. Tcsh was an advanced shell in the 1980s, but it's since been surpassed by bash and zsh. May 22, 2011 at 15:39
  • Short of, as Gilles intimates, moving to a modern shell, no.
    – jasonwryan
    May 23, 2011 at 4:01
  • @Giles - Do you imply this feature I'm looking for is supported in zsh ? If so, can you give a link/let me know how this can be enabled in zsh ?
    – TCSGrad
    May 23, 2011 at 4:14
  • @shan unix.stackexchange.com/questions/6094/…
    – jasonwryan
    May 23, 2011 at 4:37
1

There is a fancy answer to this, which could involve programmatically filtering the history right before quitting each terminal. But instead of doing that, increase the size of the history. In your shell start-up script, write 'set history=XXX' and 'set savehist=YYY' where YYY <= XXX. 'history' is the number of commands saved within a session, savehist across all sessions (saved when you close the terminal). See http://unixhelp.ed.ac.uk/shell/tcsh_hist1.html and http://unixhelp.ed.ac.uk/shell/tcsh_hist2.html.

If you want to edit the defaults for the entire machine, you can try looking for tsch.defaults, e.g., /usr/share/init/tcsh/tcsh.defaults. It will look something like this:

# History
set history = XXX
set savehist = YYY
set histfile = ~/.tcsh_history # History file
1
  • I already have that (my history size is 10K lines), even then, I wanted to filter out all the needless "exit" and "cd" commands thats clogging up the history.
    – TCSGrad
    May 22, 2011 at 5:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .