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

Suppose I do the following in zsh

cd ~
cd dir1
cd dir2
cd dir3
evince foo.pdf

zsh writes exactly the same in its history file.

Now my question is whether it is possible to have

cd ~
cd ~/dir1
cd ~/dir1/dir2
cd ~/dir1/dir2/dir3
evince ~/dir1/dir2/dir3/foo.pdf

in zsh history instead. I.e. that zsh remembers only full paths.

share|improve this question
Related (but different): Can I have my shell history record how wildcards expanded? I don't think there's a way to change what's recorded in the history, but you can clumsily record extra stuff in parallel. – Gilles May 7 '11 at 12:42
Similar question in bash – Gilles Apr 16 '12 at 23:28
A simpler and better alternative would be if zsh could record the PWD of every command in its history. So before executing a command from history it could prompt you if your current PWD dosesn't match the command's PWD – HRJ Nov 6 '14 at 11:06
Just found out that oh-my-zsh has a plugin for per-directory-history! – HRJ Nov 6 '14 at 11:14

Not in a general way, because the shell has no way to know whether a given argument is a relative path or not. Of course it could use some heuristics (similar to the ones used for completion), but this might be too error-prone.

share|improve this answer

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.