Speed Up a Slow Terminal by Clearing Log Files
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 app launch speed back:
Fix a Slow Terminal Launch Time by Clearing Log Files in Mac OS X
At the command line, use the following syntax:
Now you’ll want to verify that you are in the proper directory by listing the .asl log files:
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:
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 2: 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
The bottom line is, be cautious with sudo and rm commands, particularly when wild cards are in use.
Did this sped up the launching of Terminal app for you? This trick continues to work in all versions of OS X, so if your Mac has a slow launching Terminal, give this a try and let us know in the comments.
Thanks a lot, it works like a charm.
You don’t need the -r option, which is used to traverse subdirectories under “asl”. This is all you need:
sudo rm -f /private/var/log/asl/*
I have been troubled by slow terminal since upgrade to Sierra for quite long time. I’ve tried all of above solutions, but sadly none of them ease the problem.
At least on my mac, that slowness was found caused by the transparency of terminal app background. Once turned off transparent background, terminal got full speed back.
Setting the login shell to a specific shell worked better than the other options.
Holy crap, thank you so much. I was getting so annoyed.
Thanks. This is huge. Terminal load would take 5-10 secs before. Now it’s instant. My man.
Thanks for the tip, terminal loads a lot faster now.
Even safer than deleting them would be to move them to the trash: `sudo mv *.asl ~/.Trash`
[…] 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 […]
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
Before this, Terminal startup was >10 secs, freezing the whole system. Now <1 sec again.
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.
[…] Quelle: OSXDaily.com […]
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.
I’ve just posted another solution on reddit:
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:
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:
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…
Thank you for this how to … but do you realy think, that beginners have a Problem with a slow starting Terminal? ;-)
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.
Die Diskussion wie man ein paar Dateien löscht ist ja putzig :-).
Dachte ich auch gerade. Hätte noch ca. 20 weitere Lösungen, wie so etwas gefahrlos geht :-)
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)
Why not just use find’s -delete option instead of piping to xargs?
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.
[…] can likely fix it with these simple instructions. Share this:PrintDiggEmail Post a comment | Trackback […]
you can open the folder with Finder!
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
That was awesome! From 30 seconds of terminal load, to instant.. thank you!
[…] 出处：osxdaily.com […]
[…] Speed up a slow Terminal by clearing log files. […]
! 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
and check the section HISTORY EXPANSION
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.
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?
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.
[…] 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. […]
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 !$
Thank you Gazzer, I updated the instructions to reflect your approach since it is indeed safer.
[…] this article, which fixed the issue, immediately. Nicely […]
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…
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.
This worked like a charm. Thanks!
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.
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.
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.
Thanks. That helped. Being a unix guy, I didn’t think I needed to do manual log file maintenance on OS X.
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?
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.
new command is much better thank you
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.
Thanks now my terminal ist much faster.
Before it needed 5-10 sek to load everything.
just turning it into one long command might make it easier:
sudo rm -rf /private/var/log/asl/*
rm is dangerous for newbs