Apple UNIX
The underwater operating system of Apple SnowLeopard is based on Unix. So use the power of Unix in Apple Mac.
Useful Unix Utilities
Program | Description | Usage Example |
---|---|---|
bc | Basic Calculator, type 2+2 and press return. | |
kill | Max OS X offers no shortage of ways to cut the cord on programs that seems to be locked up or running amok. Use the Activity Monitor or use kill.
First get the ID number running top. |
|
open | Launch programs | |
ps | Process Status (ps) is another way to get a quick look at all running programs. For the best results use the -e and the -f flags. | ps -ef |
shutdown | Shutdown with the -h flags has its advantages, because it gives the user more control. | shutdown -h |
tar, gzip, zip | Compressed Archive files | |
top | Running top (table of processes) lists every program currently running. | top -u |
xattr | Manage the extended attributes of Mac files, invisible metadata describing all kind of characteristics of every file. | |
alias | Shortcuts for commands | alias la='ls -Al' |
nano, emacs, vim | editors | |
grep | Grep is a filter and is used in combination with other programs. | |
find | Terrible powerful program with a lot of features. | find . -name "fn" -type f -print 2>/dev/null |
mdfind | MedaData find | mdfind 'kMDItenFlashOnOff == "1"' |
launchd | Launching System Programs | |
ftp | File Transfer Program |
Example Process Finding
If you are running a terminal program, you may wanna find if it is still running using one of the above tools.
Assume you are running the following program which runs in an infinite loop (forever) in a Terminal window.
<syntaxhighlight lang="bash">
$ php FormulaExec.php
</syntaxhighlight>
To see the program PID you can use: <syntaxhighlight lang="bash"> $ ps -e
PID TTY TIME CMD 1 ?? 2:44.97 /sbin/launchd 46 ?? 0:48.23 /usr/sbin/syslogd ... 528 ttys000 0:01.81 login -pfl HaFrMpro /bin/bash -c exec -la bash /bin/bash 542 ttys000 0:00.08 -bash 3002 ttys000 0:00.01 tail -f -n 64 /Applications/MAMP/logs/php_error.log 536 ttys001 0:01.76 login -pfl HaFrMpro /bin/bash -c exec -la bash /bin/bash 644 ttys001 0:00.18 -bash
10842 ttys001 0:00.11 php FormulaExec.php
537 ttys002 0:01.77 login -pfl HaFrMpro /bin/bash -c exec -la bash /bin/bash 668 ttys002 0:00.76 -bash
10969 ttys002 0:00.00 ps -e
...
$ </syntaxhighlight>
If you use: <syntaxhighlight lang="bash"> $ ps -e | grep -i 'formulaexec' 10842 ttys001 0:00.12 php FormulaExec.php 11001 ttys002 0:00.01 grep -i formulaexec $ </syntaxhighlight>
Alternative you can use the top command which opens a monitor on top of the screen (ends by Ctrl-C): <syntaxhighlight lang="bash"> $ top top - 15:43:44 up 41 days, 20:28, 0 users, load average: 4.22, 4.07, 3.55 Tasks: 2 total, 1 running, 1 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.5 us, 6.8 sy, 37.5 ni, 54.8 id, 0.1 wa, 0.0 hi, 0.4 si, 0.0 st KiB Mem: 32142684 total, 30160744 used, 1981940 free, 1712 buffers KiB Swap: 0 total, 0 used, 0 free, 24802844 cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 harmfrie 20 0 17956 3220 2664 S 0.0 0.0 0:00.19 bash 7 harmfrie 20 0 21684 2328 1900 R 0.0 0.0 0:00.02 top
</syntaxhighlight>