Using purge command in Mac

Have you ever heard about the command purge? Hmmm, never heard about it? Well, that’s means you are view the right page.

Let me change the question.

Have you ever met a situation like this?

8GB, but full
figure 1

Holy shit, 8GB DDR3 memory is still not enough?

WTF?

Most of the time, I will blame my default browser: chrome! Usually, when I quit chrome, it will free 3GB+ memory, and my Lion system will go smoothly again.

But, chrome is not always the reason of high consumption of my physical memory. I don’t know which one is using a huge bunch of memory then leave it as INACTIVE, just as figure 1 looks like. The blue pie is huge! and the most important thing is it is INACTIVE.

What’s next?

OK, here purge comes to rescue, open your terminal, then type:

%: purge

BOOOOM! my system looks like as below, and feels much more faster!

after using purge

What happened?

The story behind the scene is relatively complicated, you can read Apple’s document. But anyway, it’s a shortcut to free your valuable INACTIVE memory.


Don’t forget to follow me @TonnyXu

Using `sed` command in Mac OS X to accomplish ‘replace in files’ in CUI

It’s easy to use sed command, right?

%: sed -i "s/old/replace/g" mysql.txt

This tip is all around the net. But! it doesn’t work with Mac!

WTF? How to make it work?

Try it yourself, I’m using Lion 10.7.3, it cost me over 30 minutes to search and read the man page.

-i extension

Edit files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be saved. It is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situations where disk space is exhausted, etc.

What is a zero-length extension? Try this:

%: sed -i "" "s/old/replace/g" mysql.txt

The empty string behind -i as -i "" is the KEY point.

Replace in multiple files

Try this:

%: find path/to/search -name "*.php" -exec sed -i "" "s/old/replace/g" {} \;

Good luck! Don’t forget to follow me @TonnyXu