Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from superuser.com May 22 '11 at 6:52

This question came from our site for computer enthusiasts and power users.

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 '11 at 4:47
Not programming. – Andrew Medico May 22 '11 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 '11 at 5:28
(Migrated from Super User at original asker's request. Originally asked on Stack Overflow.) – nhinkle May 22 '11 at 6:53

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.

share|improve this answer

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.

share|improve this answer
Really ?? Wow - thats a pretty big drawback to tcsh IMHO...Any ideas as how one might work around that ? – TCSGrad May 22 '11 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. – Gilles May 22 '11 at 15:39
Short of, as Gilles intimates, moving to a modern shell, no. – jasonwryan May 23 '11 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 '11 at 4:14

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
share|improve this answer
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 '11 at 5:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.