13 Comments

Summary:

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 […]

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

top
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
programs:
ps -aux > ~/ programlist.txt

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

You’re subscribed! If you like, you can update your settings

  1. 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.

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

  3. Grr… The “&&amp” above should just be “&&”

  4. Grr. The && above should just be &&

  5. Ugh. Beaten.

  6. 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:)

  7. “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.

  8. 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).

  9. 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

  10. 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.

Comments have been disabled for this post