Here's what I've got in ~/.zshenv (/etc/zshenv is blank)

print -P "before %D{%H:%M:%S}"
/usr/bin/time /bin/cat /dev/null
print -P "after %D{%H:%M:%S}"

If I try to start zsh, it will occasionally hang on the cat command for up to 30 seconds:

bash$ zsh -c exit
before 16:04:08
  0.00s user 0.00s system 0% cpu 0.001 total
after 16:04:29

If I open another new zsh immediately afterwards, the hanging never happens. If I wait at least two minutes first, it almost always happens.

Why is this happening? How can I stop it?

This is zsh-4.3.11 on CentOS 6.9.

  • 3
    Any clue from strace -f zsh -c exit? Aug 24, 2018 at 20:34
  • 2
    Is it only cat? And only when passed /dev/null? What about /bin/true or paste /dev/null? Aug 24, 2018 at 20:43
  • It originally was cating a different (empty) file, and I switched to /dev/null to see if the choice of file made a difference. Looking at the output of time above, I think that's the command that's hanging now, not cat. Maybe it's the first non-native call? Originally I had multiple cats, and it was always only ever the first one that hung. I'll try strace when I get in Monday.
    – rampion
    Aug 25, 2018 at 16:17
  • make it strace -fTtt zsh -c exit for timing information. Aug 25, 2018 at 21:37

1 Answer 1


The slowdown was due to hash. One of the default directories the local SAs had put in my path had 8k+ entries in it.

Using the strace command suggested by Stéphane Chazelas revealed that the stat() calls used by hash were causing the slowdown.

If I opened another shell immediately afterwards, the each stat() call was up to 180x faster (presumably due to caching), which explains why the slowdown didn't happen every time.

As a fix, I removed the directory from my PATH. If I need any executables from there, I'll just put symlinks to them in a smaller directory in my PATH.

You must log in to answer this question.

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