How Can I Speed Up Terminal.app or iTerm on Mac OSX?

41

36

Every time I launch either iTerm or Terminal after not using it for a few hours, it takes anywhere from 10-20 seconds to return a prompt. The screen is blank, and although I can type I can't actually run any commands.

If I quit either application, subsequent launches (if done relatively soon thereafter) are quite fast. The slowness only seems to occur if the app wasn't running for a few hours.

I'm running OSX 10.5.7 on a MacBookPro. I have the exact same setup on another computer, with no slow downs.

Any ideas how to speed things up again?

pmaiorana

Posted 2009-08-28T15:08:58.420

Reputation: 548

I love how this question is asked and answered by two anonymous users with random numbers. I don't see this pattern that often! :) – cregox – 2011-04-13T15:59:54.487

Answers

39

Try deleting the Apple system log files in /var/log/asl/:

sudo rm /var/log/asl/*.asl

This did the trick for me.

user12544

Posted 2009-08-28T15:08:58.420

Reputation: 414

+1. Worked like a charm even though as one of the other answers suggested I have a non-trivial .bashrc. – alesplin – 2011-02-05T20:48:52.057

7

As pointed out on OsXDaily, I'd recommend using sudo rm -rf /private/var/log/asl/*.asl instead because it's safer as it 1) only deletes the log files and 2) avoids cding into the wrong directory and removing all files.

– Matthew Rankin – 2011-02-24T12:34:15.730

3(ASL = Apple System Log) – Arjan – 2009-09-28T08:55:10.007

1Anyone have any idea why the size of system logs effect how fast the terminal opens? – James McMahon – 2012-08-02T04:10:56.473

3@JamesMcMahon The login process seems to read all files and folders on the top level of /var/log/asl. Try running sudo opensnoop | grep /var/log/asl. – Lri – 2012-08-06T09:59:30.977

Ah, so the terminal wasn't a login shell it would open up faster. Interesting. – James McMahon – 2012-08-06T14:50:10.810

What are these logs for? How are they different than shell history? – Nathan Long – 2013-01-10T13:41:35.957

You can also go into Terminal.app preferences and on the startup tab, set the command to your shell instead of the default login. login apparently reads the logs to find the last login time. – Michael Mior – 2013-02-03T15:34:07.383

30

Another tip might be helpful:

Change start up shell from default /usr/bin/login to /bin/bash -l, or /usr/bin/zsh if you use zsh.

That might make your Terminal/iTerm2 launch in light speed!

  • For Terminal: Preferences → Startup: Change from "Default login shell" to "Command: /bin/bash -l"

  • For iTerm2: Preferences → Profiles → General → Command: Change from "Login Shell" to "Command: /bin/bash -l"

user150579

Posted 2009-08-28T15:08:58.420

Reputation: 301

apparently using /bin/bash -l isn't enough for yosemite (anymore?), for other deatils, see http://apple.stackexchange.com/questions/41743/how-do-i-speed-up-new-terminal-tab-loading-time

– rogerdpack – 2015-02-19T20:42:23.083

Deleting the log is fine, but after a short while the bash login process is slow again. The /bin/bash/ -l is a more forward-looking solution. – michelgotta – 2016-10-19T07:24:17.383

both removing the asl and changing to /bin/bash -l didn't make anything faster for me. any other thoughts for troubleshooting this? – Justin – 2017-02-09T18:42:45.100

did this change break your theme? – Chris Hough – 2017-06-26T00:18:12.743

2This sped up new tab loading considerably. – Sindre Sorhus – 2012-09-05T04:00:46.507

1Can't say how much this helped me. Solved ~6 months of slow terminal performance in 1 second. – Sam Stern – 2013-10-21T15:36:43.993

/bin/bash -l works for me! – Phill Pafford – 2013-11-25T16:24:41.600

For those preferring to use the MacPorts bash: /opt/local/bin/bash -l – Ioannis Filippidis – 2013-12-05T00:08:32.313

9

Am I required a certain reputation to comment on posts? Anyway clearing the system logs did it for me as well, thanks. I have tried to patch path_helper with the patch here: gist.github.com/123525, as suggested in a comment on http://mjtsai.com/blog/2009/04/01/slow-opening-terminal-windows/ (referenced earlier in this thread) but to no avail. I get a cryptic error. However, that patch should speed up terminal.app launch.

addition: As I mentioned, clearing the logs did the trick for me, but the problem continues to emerge as the logs continously grow bigger after I've removed them. I found that "tweaking" /etc/asl.conf has given me a more permanent solution. The modification is to log only messages that are categorised as "critical" or more critical than that, as opposed to logging "notice" category and every more critical than that. Also, I disregard messages from ftp, mail, local0, local1. Here's a paste of my /etc/asl.conf:

 ##
 # configuration file for syslogd and aslmanager
 ##

# redirect com.apple.message.domain to /var/log/DiagnosticMessages
? [T com.apple.message.domain] store_dir /var/log/DiagnosticMessages exclude_asldb

# authpriv messages are root/admin readable
? [= Facility authpriv] access 0 80

# remoteauth critical, alert, and emergency messages are root/admin readable
? [= Facility remoteauth] [<= Level critical] access 0 80

# broadcast emergency messages
? [= Level emergency] broadcast

# save kernel [PID 0] and launchd [PID 1] messages
? [<= PID 1] store

# save everything from emergency to notice
#? [<= Level notice] store
? [<= Level critical] store

# save lpr info level and above
#? [<= Level info] [= Facility lpr] store

# save all mail, ftp, local0, and local1 messages
#? [= Facility mail] store
#? [= Facility ftp] store
#? [= Facility local0] store
#? [= Facility local1] store

tmadsen

Posted 2009-08-28T15:08:58.420

Reputation: 1 079

1

Welcome at SU. Yes, 50 reputation is needed, but there's more to know, so head over to http://superuser.com/faq right away! ;-)

– Arjan – 2009-09-28T10:38:04.887

7

From an article I read a couple weeks ago: Slow Opening Terminal Windows

/usr/libexec/path_helper is terribly slow at loading /etc/paths If you remove all the entries in /etc/paths and ensuring that those items are available in your .bash_profile this will resolve the issue. It did for me anyway.

Chealion

Posted 2009-08-28T15:08:58.420

Reputation: 22 932

Is it still the case? path_helper doesn’t seems slow… – Franklin Yu – 2018-01-09T08:07:10.413

Coincidentally someone rewrote path_helper and it's available at: http://github.com/mgprot/path_helper

– Chealion – 2009-10-26T19:46:38.537

1

If the terminal application has loaded but you don't have a prompt yet then it's your shell taking a while to initialise.

This probably means you have too much or something time consuming in your .bashrc (assuming you use bash).

Mike McQuaid

Posted 2009-08-28T15:08:58.420

Reputation: 3 639

This might be the problem I'm having, do you know how I can check If I'm using bash where I can access the .bashrc file? – alvincrespo – 2011-10-25T13:45:51.467

1

My guess is that over time, something is using a lot of memory. When you startup a terminal after not using it for a while, some memory has to be made available by swapping its contents out to disk. If you kill the terminal process and restart it relatively quickly the memory is still available and it starts up quickly. This should happen with other applications as well.

You should monitor your memory usage with Activity Monitor and see if you can tell where it is going.

KeithB

Posted 2009-08-28T15:08:58.420

Reputation: 8 506

He said that the Terminal window was open which means the process has loaded. – Mike McQuaid – 2009-08-30T10:52:59.673

1@Mike, I am not sure that once the Terminal window is shown, everything has loaded? Still, if the above would be true for Terminal, then any program would launch slowly. I don't think Terminal needs a lot of resources (6.5/31.7 real/virtual on my Mac), so @pmaiorana: how much memory does Terminal needs on your Mac? – Arjan – 2009-09-28T08:52:36.223

0

If you are using oh my zsh with composer plugin, just remove it.(I'm running OSX 10.14 on a MacBookPro)

# .zshrc
plugins=(git) # composer will slow you down

CloudyCity

Posted 2009-08-28T15:08:58.420

Reputation: 1

0

Open /etc/profile and add the line PATH="" so it looks like this:

if [ -x /usr/libexec/path_helper ]; then
    PATH=""
    eval `/usr/libexec/path_helper -s`
fi

davidcondrey

Posted 2009-08-28T15:08:58.420

Reputation: 1 345