How can I display a message when I cd into a specific directory? This directory is a local one, and I just need a reminder when I go into it from the terminal.


If I were you, I would toy around with something like that in my shell configuration file (e.g. ~/.bashrc):

reminder_cd() {
    builtin cd "$@" && { [ ! -f .cd-reminder ] || cat .cd-reminder 1>&2; }

alias cd=reminder_cd

This way, you can add a .cd-reminder file in each directory you want to get a reminder for. The content of the file will be displayed after each successful cd to the directory.

gim@tenebreuse ~/tmp % echo 'warning: this directory is pure junk' > .cd-reminder
gim@tenebreuse ~/tmp % cd ..
gim@tenebreuse ~ % cd tmp
warning: this directory is pure junk
gim@tenebreuse ~/tmp % 
| improve this answer | |
  • 1
    Cool idea by the way! I like it, and maybe I'll use it too :-) – Stéphane Gimenez Aug 11 '11 at 0:52
  • Not importat in this case, but in general is good abit to always double quote $@. – enzotib Aug 11 '11 at 15:04
  • 1
    Thanks, I'm now wondering if there is any case where $@ should be preferred over "$@" – Stéphane Gimenez Aug 11 '11 at 18:49
  • 1
    You should use $@ or $* (they are the same thing when unquoted) when you want IFS wordsplitting to occur. – Chris Down Sep 16 '11 at 20:09
  • If you use this method don't forget to alias pushd and popd also. – mVChr Nov 8 '15 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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