Speed Up a Slow Terminal by Clearing Log Files

May 6, 2010 - 47 Comments

mac os x terminal The Mac OS X Terminal can become slow to launch over time, but there’s an easy solution to speed it up again.

By deleting the Apple System Logs, you can shave the lag in opening and launching new Terminal windows/tabs dramatically, in my case from about a three second delay to instantaneous!

Here’s how to delete the log files and gain your Terminal launch speed back:

At the command line, use the following:

cd /private/var/log/asl/

Now you’ll want to verify that you are in the proper directory by listing the .asl log files:

ls *.asl

Finally, if only .asl files turn up as the result, type the following command to delete them:

sudo rm !$

Update: we adjusted the above commands per user comment, it is now safer for more novice users. Here’s the old command maintained for posterity, it’s been struck out because it’s a bit more risky for beginners to follow:

At the command line type the following:
cd /private/var/log/asl/
then, inside that directory, type:
sudo rm -rf *.asl

Warning: be absolutely certain that you only type the sudo rm -rf command INSIDE the /var/log/asl/ directory! rm -rf * deletes all files in a directory, no questions asked, so if you perform that task in the wrong directory (like home folder) you are going to have a serious problem! I’m assuming you have moderate experience in the command line environment – if you do not, you probably won’t need this tip anyway.

Update: As Marc points out in the comments, it’s safer to specify deleting only the log files. Above command has been altered to reflect this. An alternative and shorter command is this one:
sudo rm -rf /private/var/log/asl/*.asl

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Bill Ellis in Command Line, Mac OS X

47 Comments

» Comments RSS Feed

  1. Sandcastles says:

    just turning it into one long command might make it easier:

    sudo rm -rf /private/var/log/asl/*

    rm is dangerous for newbs

  2. Testie says:

    Thanks now my terminal ist much faster.
    Before it needed 5-10 sek to load everything.

  3. Marc says:

    You could also make it a much safer tip by specifying *.asl
    All of the logs, and nothing but the logs, would still be removed.

  4. namhar says:

    hey is it -rf or f in the command you say f* and then in the warning you are saying rf* so which one is it?

    • Editor says:

      the -r flag specifies removing directories contained within as well, -f just forces the removal of the files without prompting and regardless of the file permissions.

      The command can be:

      sudo rm -f /private/var/log/asl/*.asl

      Putting it all in one line and making it safer by specifying only *.asl files (logs) but this will not remove the directories contained within.

      - Manish

  5. Scott says:

    Thanks. That helped. Being a unix guy, I didn’t think I needed to do manual log file maintenance on OS X.

  6. Rob C says:

    This worked great. Thanks!

    @Scott: they might eventually get cleaned up like on any other unix box, but if your machine isn’t on all the time the cleanup scripts might never execute.

  7. Stormchild says:

    Thanks, this was driving me nuts. Problem solved.

    BTW, my machine is on all the time, so apparently these particular files never do get cleaned up automatically.

  8. demoman says:

    Hey, when i did it, it said wrong command and it will be reported or sompin like that the reported thing kinda scared me whats that all about?

    • I believe you’re talking about the following message:
      (username) is not in the sudoers file. This incident will be reported.

      This means that your account is not an administrator account, and you cannot remove the files. You will have to run the command in an administrator account.

  9. gilliss says:

    This worked like a charm. Thanks!

  10. Stormchild says:

    Unfortunately, within a week or so, the terminal is slow again. Would really prefer not to have to run this every week.

    • If you want to automatically run this script every once in a while, you can use cron jobs. Here are instructions to run the script every other hour. If you want to change how often it runs, I’d read more about cron jobs on the internet.

      In terminal, type:
      sudo env EDITOR=nano crontab -e

      This will open the crontab file. Add the following to it:
      0 */2 * * * rm -rf /private/var/log/asl/*.asl >/dev/null 2>&1

      Save the file by pressing Control + X. Then, press y, and then enter.

      • After looking on the internet more, it seems 0 */2 * * * runs every two hours, and 0 0-23/2 * * * will run it every other hour. I can’t figure out what the difference is, but I just thought I would add that…

      • Liselore Vermeulen says:

        solutions using crontab are *neat*,
        however one should be carefulll in update cycles,

        Apple is in a move towards launchd,… and e.g. the update from Tiger to Leopard… did clear/overwrite the /var/cron/tabs directory.

  11. [...] this article, which fixed the issue, immediately.  Nicely [...]

  12. Gazzer says:

    hfs, that’s dangerous.
    Why are you specifying -rf with files? Root, recursive force delete plus a wildcard? I hate to think what would happen if a newbie made a mistake with the cd followed by an erroneous space.

    Make it safe
    $ cd /private/var/log/asl/
    $ ls *.asl
    [check the output, if it's not a list of files ending with .asl STOP]
    $ sudo rm !$

  13. [...] seem to help a lot, but likewise, I’m not sure why. A little research also shows the folks at OS X Daily had similar results. If you’ve got a better explanation, let’s hear it in the comments. [...]

  14. Jesse says:

    first of all I’m totally new at this, I’m trying to free up some space (51GB is an inexcusable amount for my private/var/log to be taking up)
    when i follow the instructions, before it deletes anything, it tells me that the argument list is too long
    what should i do?

    • Liselore Vermeulen says:

      you could split up your query,.. by using
      *year* with year the year (like 2011 now) for which you’d like the files to be removed.

      sudo rm -f /private/var/log/*2010*.asl

      and repeat with other years.

  15. for the huge inspect, but I’m rattling loverlike the new Zune, and desire this, as fortunate as the reviews any added bed shorthand, module exploit you determine if it’s the just action for you.

  16. venividivici says:

    what’s !$

    • Liselore Vermeulen says:

      caesare,

      ! is the default history expansion character.

      !$ will be replaced during shell expansion by the argument of the last command.

      rm -f $!
      will henceforth be replaced by
      rm -f *.log

      since it’s invokation was preceded by ls *.log

      for more info, execute
      man bash
      and check the section HISTORY EXPANSION

  17. [...] Speed up a slow Terminal by clearing log files. [...]

  18. Vitor says:

    That was awesome! From 30 seconds of terminal load, to instant.. thank you!

  19. Liselore Vermeulen says:

    with the danger of this instruction… even the fix (imagine a misplaced space or two…
    sudo rm -rf / private/var/log/asl/*.asl
    would have some renowned f*cked up results…

    hence maybe one could do instead:
    cd /private/var/log/asl && sudo rm -f *.asl

  20. mas says:

    you can open the folder with Finder!
    open /private/var/log/asl

  21. [...] can likely fix it with these simple instructions. Share this:PrintDiggEmail Post a comment | Trackback [...]

  22. chris says:

    How on earth can you possibly think that the command is safe for novice users:

    sudo rm !$

    Now the users think “hey cool, this command deletes those bad logs,” and the next time they run it, it deletes some random other thing that they have just been using.

  23. Douglas says:

    Better than all the above:

    find /private/var/log/asl -type f -name ‘*.asl’ -ctime +7 -print0 | xargs -0 rm -f

    (will delete all _files_ (no dirs) named something.asl that are older than 7 days, and will not have problems with strange characters (spaces!) in filenames, subdirectories, or a lot of files)

  24. manuel says:

    Die Diskussion wie man ein paar Dateien löscht ist ja putzig :-).

  25. Frank says:

    Don’t use -r if you only want to delete files. This is safer. And since you edited your commands a couple of times to suit novices al well this would be a good addition as a best practice.

    Use -r not because you use it every time you delete something. Try getting used to not use parameters that make no sense in for the current intended action.

    And for deleting files adding parameter -r is pointless. It just adds potential damage i.e. when using a fileglob that accidentially matches more things that you intended to.

  26. volker says:

    Thank you for this how to … but do you realy think, that beginners have a Problem with a slow starting Terminal? ;-)

  27. preller says:

    I’ve just posted another solution on reddit:
    http://www.reddit.com/r/apple/comments/lzchr/speedup_terminal_by_deleting_log_files/

    Here’s the post:
    Every time you launch a terminal window or tab, at first a “login” process is started which itself starts your shell. The good thing is that “login” is open source and everyone can check why it’s doing that (and maybe fix it, lol): http://opensource.apple.com/source/system_cmds/system_cmds-541/login.tproj/

    In detail the login process is started with following arguments:
    login -pf

    This login process reads for whatever reason every log file which is stored in /var/log/asl.
    You can check that with: sudo opensnoop | grep “/var/log/asl”

    So, the more log files are stored there the longer it takes to start up a shell in your terminal.

    I just found out that if you change the “Shells open with” preference (http://cl.ly/BWyZ) in your terminal settings to “Command (complete path) and put in your default shell path into the textbox “/bin/bash” (it’s /bin/zsh for me, but that doesn’t matter) the login process is started with the following arguments:

    login -pfq

    The -q argument forces quiet logins. Those log files aren’t being opened again, you can check that with opensnoop again. The only difference is that you won’t get those fancy “Last login: Fri Nov 4 12:33:34 on ttys011″ Messages anymore. I think that’s a better workaround than deleting those log files every now and then.
    I hope everyone understood me, my english is really bad…

  28. Christopher says:

    Seems to me that the by far safest way of deleting these files would be

    sudo aslmanager -size 1

    It will leave a file or two, but those are, it seems, the ones currently in use, and it makes sense to keep those.

    The man page also says aslmanager runs regularly and you can set set max_store_size in /etc/asl.conf to avoid having a cron job or fiddling around with launchd scripts, but I haven’t tried that.

  29. my2cents says:

    My two cents, I did

    1) Christophers’ way: cleaned up logs
    sudo aslmanager -size 1

    2) prellers’ way: this solved logs accumulation problem for future. Followed instructions at: http://www.reddit.com/r/apple/comments/lzchr/speedup_terminal_by_deleting_log_files/

    Everything works perfectly. Terminal launches in microseconds now. Thank you guys for the analysis and solution.

  30. Mikko says:

    Thanks.

    Before this, Terminal startup was >10 secs, freezing the whole system. Now <1 sec again.

  31. Darren says:

    There’s a much simpler and safer way to solve this problem.

    Slow startup is caused by /usr/bin/login, which, for reasons unknown, loads those .asl files at startup.

    Solve the problem by setting Terminal to use non-login shells. Preferences -> Startup -> Shell Opens With: /bin/bash

  32. [...] to provide information on the last login. One way to speed up launching a new terminal window is to delete those .asl log files, but you can achieve a substantial speed boost by simply setting Terminal to open a shell rather [...]

  33. Nathan says:

    Even safer than deleting them would be to move them to the trash: `sudo mv *.asl ~/.Trash`

  34. Marcel says:

    Thanks for the tip, terminal loads a lot faster now.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates