I have just noticed that command line utilities such as ls
(/bin/ls
), touch
(/usr/bin/touch
), cat
(/bin/cat
), etc. are very slow when I run them from Terminal or iTerm on my MacBook. For example:
-
ls
'ing while in an empty directory takes 1 second (it also takes 1 second in a non-empty directory, both with lots of files or with a few files); -
touch
'ing a new file takes 1 second (it also takes 1 second totouch
an existing file); -
cat
'ing an empty file takes 1 second (there is also a 1 second lag before anything happens when Icat
a non-empty file).
I have tried to diagnose this in many ways but to no avail. I do not think this is a filesystem issue, since:
-
I have run Disk Utility and it reports no problems.
-
Everything seems to be working just fine in Finder, e.g. directory contents are shown instantaneously in Finder.
-
I installed GNU coreutils using Homebrew and tried using
gls
,gtouch
,gcat
, etc., and all of the operations I listed above happen instantaneously when run with the GNU version instead.
Any ideas on what could be going on? Any ideas on how to fix this?
EDIT: When I reboot the computer, or try a different user, these issues go away temporarily, but after a few minutes they seem to reappear again. Another strange thing that I noticed:
$ time date
Wed Jan 28 10:07:11 PST 2015
real 0m0.151s
user 0m0.001s
sys 0m0.003s
$ time date
Wed Jan 28 10:07:13 PST 2015
real 0m0.029s
user 0m0.001s
sys 0m0.002s
$ time date
Wed Jan 28 10:07:16 PST 2015
real 0m1.005s
user 0m0.001s
sys 0m0.002s
$ time date
Wed Jan 28 10:07:18 PST 2015
real 0m1.005s
user 0m0.001s
sys 0m0.002s
This happens for all the utilities I've tried, mkdir
, scp
, sftp
, more
, cat
, etc.: The first time I run it after a reboot, it's medium-slow. The second time I run it, it's sorta-fast. All subsequent times I run it, it's slow.
Best Answer
I actually figured out the issue today. It was caused by a piece of anti-malware software called Sourcefire AMP (Advanced Malware Protection). All of my issues went away after I disabled/uninstalled it.
I'm guessing that it was doing something like putting a delay on things in
/bin
,/usr/bin
, etc. for "security reasons"... I'm guessing the GNU tools were not delayed because they weren't in the "blacklisted" directories.