Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How can i speed up the terminal startup in Lion?

I'm not referring to the startup of the Terminal application, but to the startup terminal windows, like when i open a new tab.

I don't have anything in my .bash_profile file and i run rm -rf /private/var/log/asl/*.asl every 4 hours (which clear those files that usually make terminal slow ).

Currently, when i open a new tab, it takes 3-4 seconds until i can run something.

share|improve this question
1  
Perhaps there is something else wrong with your system? It shouldn't be that slow. Sometimes it takes a second or two for me, but usually it's only a split second. And I have a fair bit in .bash_profile (also check ~/.profile by the way). Also: note you can start typing while bash is loading, and usually what you type will be copied to the command prompt once it's ready. –  Abhi Beckert Feb 26 '12 at 0:44
    
Are you using a network account or a network home directory? Is Terminal responsive to user input while it's creating the terminal? Does it display the spinning busy cursor? –  Chris Page Feb 26 '12 at 11:56
1  
To find out where Terminal is spending the time, open Activity Monitor, select Terminal and click the Sample Process toolbar button, then immediately go to Terminal and create a new window/tab. The sample may provide a clue as to where the time is going. Also, watch the process list in Activity Monitor: if "login" or "bash" (or whatever shell you're using) appear in the list during the delay, that means the delay is likely occurring in one of those two programs and not Terminal. –  Chris Page Feb 26 '12 at 11:58
    
Have you checked your PATH variable? I noticed that mine was absurdly long with many repeats due to some confusing .bashrc going-ons. I removed the repeats and everything sped up! –  190290000 Ruble Man Mar 27 at 22:47

4 Answers 4

Short Answer:

  • Open Terminal Preferences
  • Select the Startup tab
  • Select "Shells open with: Command", and use "/usr/bin/bash" as the command.

Important: Do not use "/bin/bash" as the startup command. If "/usr/bin/bash" does not exist on your system, create a symbol link: sudo ln -s /bin/bash /usr/bin/bash

To verify the fix:

  • Open a new Terminal windows.
  • "Last Login:" should not be displayed
  • Open the inspector (Command + I) and select the Info tab.
  • The command should read login -pfq username /usr/bin/bash

Important: If the login command does not include the -q parameter, then you have not fixed the problem.

Details:

Terminal uses /usr/bin/login to launch each new window/shell. By default, /usr/bin/login will display the date of your last login. To get this last login date, it searches the ASL (Apple System Log) database at /var/log/asl/. These log files can be very heavily fragmented and it's this file fragmentation that causes the delay when opening a new window or tab.

To see this in action, run sudo opensnoop | grep login in a Terminal window, then open a new Terminal window.

To prevent /usr/bin/login from doing this ASL search, you must pass the -q parameter. The only way Terminal will pass the -q parameter is when you specify a custom shell command in the Preferences.

Note: .hushlogin does not prevent /usr/bin/login from doing the ASL search. This can be confirmed by using the opensnoop command above.

share|improve this answer
2  
Do you know why -q is added if the command is a symlink to /bin/bash but not if it's /bin/bash? –  Lri Nov 18 '12 at 15:16
3  
@LauriRanta It seems to be a bug in the 10.7 and 10.8 Terminal. When the startup command is set to /bin/bash it behaves as if the Default Login Shell was selected. Any command other than /bin/bash will work correctly, so using /usr/bin/bash is just a workaround. This bug is not present in Snow Leopard. –  Darren Nov 18 '12 at 15:34
    
This is really great and helpfull answer. For me, I was having the same issue on my MacBook Pro. I just changed the settings jast as above and the terminal start up fixed again. What is surprising me that : I then rechanged it back to the original settings. And it is still very fast. Weird bug needs to be solved by Apple. ( OS X 10.8.2 ) –  Olgun Kaya Dec 28 '12 at 5:53
3  
@Darren have you reported this suspected bug to Apple? If not, please could you do so through: bugreport.apple.com –  Graham Miln Dec 31 '12 at 16:55
    
Whats exactly the trick for bash to run from /usr/bin/bash ? –  Ans Oct 22 '13 at 22:40

Create an empty file in your home folder called .hushlogin; this will significantly decrease the time it takes for a Terminal.app tab to appear.

When you create a new Terminal tab, you are going through the login process. The process involves fetching various information about your previous login session, message of the day, and displaying system messages. This can be the source of significant delays. Try hushing these messages to see if the delay disappears.

You can create the .hushlogin file in Terminal.app using the following command:

touch ~/.hushlogin

The file will take effect immediately.

You can learn more about the .hushlogin file and the login process in general in the login manual.

share|improve this answer
4  
.hushlogin does not actually solve the problem. This can be confirmed by using opensnoop. See my answer below. –  Darren Nov 18 '12 at 11:47

Reduce your history to something between 4 and 10 thousand lines and perhaps try quitting and discarding all saved windows. I have seen both make a difference on slower machines - especially ones without SSD for storage.

share|improve this answer

It is all about investigating the cause. You can see what's being done while the process starts by inputing bash -x which will print out the process of starting up the shell.

Personally, I only notice the delay between activation and de-activation of the app and in the first tab created after a period of activity. It always makes me think that it is about memory pages being moved around.

share|improve this answer

Your Answer

 
discard

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.