Quick Unix Tips


Reader Wieger van der Burgt wrote in with a nice list of Unix goodies. Some of the tips expand on things I’ve written about before, while others may be new to you. (Especially if you’ve only been following along here at The Apple Blog for Unix tips as of late.)

So while I work on the weekly Unix Tip I was planning for this week, I’ll leave Wieger’s list for your viewing pleasure. Thanks for the contribution Wieger!

cd ~/
your home dir

ps -aux
get a list of what is running and stop

same as above except it keeps showing

touch [filename]
making a new file, for example a text file:
touch test.txt

touch /test.txt
doing this in another folder – the root folder in this example

ls > ~/test.txt
put the output in a text file named test.txt
this is possible with all the comands. so if you want a list of running
ps -aux > ~/ programlist.txt

[command 1] | [command 2]
run command 1 and wait till it is finished then command 2


D. Adam Karim

just in case someone else finds this, if you really want ‘ps -aux’ to still work, then in your .profile do:

export COMMAND_MODE=legacy

Giovanni Caristi

In Leopard, ps -aux won’t work anymore, as I painfully discovered.
A “ps aux” wrapper is provided:

The biggest change is in the interpretation of the -u option, which now displays processes belonging to the specified username(s).
Thus, “ps -aux” will fail (unless you want to know about user “x”). As a convenience, however, “ps aux” still works as it did in Tiger.

What is Unix?

To what audience are these ‘tips’ intended? Listing touchm which one almost never uses, without listing the handy pwd seems unusual. If this is meant as an introduction (and by including cd it must be), then there are some vital commands that have been left out. cat, vi, ls without the redirection of output…

Eric F Crist

In addition to above, if you use the following command, it will run the first, and only run the second if the first exited ‘0’ (zero), meaning successful:

command && command

You can do this as many times as you want:

touch test.txt && touch test.txt2 && touch text.txt3

If you didn’t have write perms to the directory you’re trying to create the files in, the first would exit 1, and all other commands would simply not be executed.


command1 | command2

Does not run command1 followed by command2. The pipe symbol ‘|’ “pipes” the output of command1 into the input of command2. As such, both command1 and command2 run at the same time.

For example: ps ax | grep Mail

Runs “ps” and then pipes the output of “ps” into “grep”. Grep finds any line matching the first argument. In this case, any lines output from ps that contain the word “Mail” will be output by grep.

If you want to run one command followed by another command, the correct syntax is:

command1 ; command2


ps aux
is the proper syntax.

ps awwx

On the Mac, this command will format the process list so you can actually read the entire line of the process.

For example if your terminal window is only 80 columns wide, ps aux will chop off any characters past the 80 column mark will be cut off. This is not very useful if your path is longer than the screen is wide (including the rest of the process information).


“touch” will also update the last modified date of a file if it already exists (which is where the name comes from). I know because I got in a bit of trouble with our senior UNIX admin at college when I wrote a script that would wake up every few hours and “touch” all the files in my temp directory so that they wouldn’t get deleted by another chron job that cleared out old files.


Wow cool to see my stuff on the website. I shall try to find some more nice things under the hood of OS X.
I hope you like it:)


Can’t you get to the home directory by entering cd with no arguments?


A couple embellishments:

The ~/ is not necessary in the first example; cd by itself will change the working directory to the current user’s home.

The last example is more complicated than the text lets on. The | character creates what is called a pipe. The pipe redirectes the output (stdout) of the first command into the input (stdin) of the second. See the Wikipedia “Pipeline” entry for a decent introduction. Pipes are great for things like ps -aux | grep Finder (which will find the Finder process).

If all you want to do is run commands in succession then use &&, which only runs the second if the first is successful.

Comments are closed.