Tips July 30, 2004 at 2:46 am

My Favorite OSX UNIX Tools

I’ve learned almost everything I know about UNIX on my own, and even when I’ve been shown how to do something from the command line, troubleshooting often puts me on the path of self-instructed discovery. Here are some tools I use a lot (specifically in OS X), when mapping uncharted territory.sudo – type this before a command to ‘do’ it as the superuser (root).

apropos – this command helps you locate commands and files related to a search term you enter. ‘apropos password’ yields a list of commands for working with different types of passwords, etc.

man – follow this command with the name of a command you don’t know anything about – you get a manual (man) page abou the command.

ls -la – with the ‘-la’ variable you see the listed (ls) contents of a directory with details on permissions. you also see hidden files and directories.

mkdir – make a new directory/folder

chmod – change the permissions for a file/folder

chown – change the owner for a file/folder

chgrp – change the group for a file/folder

rm – remove a file/folder (-r flag remove all file and subfolders in a folder recursively).

nslookup – deprecated in favor of ‘dig,’ but very simple to use when debugging dns. type ‘server’ at the prompt to see you dhcp and manually-supplied dns servers, and the dns name of a machine on the network to see if you get full resolution.

ping – of course used to see if a link is up, but also useful to see if there is a dns entry for a host. type ‘ping example.domain.suffix’

ssh – the best way to connect to a far-away machine – only requires one open port in a firewall, and connects via encrypted tunnel. enabled by default on OSX Server. best syntax is like this: ‘ssh -2 username@example.domain.suffix’

shutdown – a kinder, gentler version of the brutal ‘halt’ command. ‘shutdown -r now’ reboots a server fairly smoothly. ‘shutdown -h now’ shuts it down likewise. read the man page for more goodies.

dscl – tough to use, but a good way to troubleshoot open directory issues. READ the man for this one!

softwareupdate – a good command to run is ‘sudo softwareupdate -i -r’ – this install all required updates. be aware that you have to ‘sudo shutdown -r now’ afterwards…

system_profiler – does just what it says – but the output is VERY long, so use…

grep – use to get only what you want from output of a command (means ‘grab regular expression’) – a simple use would be ‘system_profiler | grep Machine’. case-sensitive.

top – list processes and their cpu load, memory state, etc. ‘top -u’ put the most expensive processes at the top. useful in conjunction with…

kill – terminate processes by their id numbers – id numbers are listed to the left of the process in output from ‘top’. example – ‘kill 1492’. adding -9 flag is sort of like swatting a gnat with a sledgehammer; sometimes its just more fun that way.

mv – use to move or rename file/folder. example of renaming: ‘mv foo.txt foo-foo.txt’ – foo.txt becomes foo-foo.txt.

cp – copies file or folder (with -r flag) to the place you specify

ditto – copies file along with it’s resource fork (with -rsrc flag) – also preserves permissions by default – very useful, read the manpage.

locate – find files containing specified terms. ‘locate secret_passwords.txt’, for example

more – specify a file after this command to view its contents safely (more will not let you make changes).

| – a symbol that means ‘pipe’ – this is one of the truly amazing gut-level features of UNIX. pipes let you send the output of one command to another command as it’s input. see my example for system_profiler. the key for this symbol is just above the return key, if you’ve never used pipes before.

pico – a simple text editor, with easy controls. not as sexy as vi, but (I think) safer if you are not a very skilled vi user. invoke with ‘sudo’ to make changes to system config files and plists.

feel free to reply with your own favorites…

(by the way, i have often found that apropos and locate are broken after a new install – fix this by running two scripts in /usr/libexec – you need the full path. ‘sudo /usr/libexec/locate.updatedb’ and ‘sudo /usr/libexec/makewhatis’)

bcirvin/

No Comments

  • pwd: the classic Print Working Directory. Helpful in those “where the heck am
    I?” moments.

    update_prebinding: This used to be essential in Jaguar days; Panther seems
    to do a better job of keeping prebinding (dynamic library linking to speed
    application launches) up to date. To redo prebinding for the whole boot
    volume:

    sudo update_prebinding -root / -force

    nmap & mtr: delightful little network tools; both need
    to be installed with darwinports or fink.
    Nmap, the standard portscanning app, is invaluable for network security
    checking. MTR is helpful for doing quick traceroutes.


    Michael T. Rose
    mjm creative services | http://www.mjmcreative.com/

    • that prebinding command sounds like it would be useful when firing up NOLF
      2!!

      :^)

      blake/


      Professional Services/Training
      MacOutfitters of Cranberry, PA
      “Fixing my mistakes, one server at a time”

  • This is slightly off topic…

    emacs -batch -l dunnet

    …but nevertheless one of my favourite NOT so useful commands in the
    terminal.

  • The obscure command sudo fs_usage -f filesys shows filesystem
    activity in real-time. You can also specify switches to monitor just certain
    processes or PID’s, or to monitor the network instead of the filesystem.
    Unfortunately I don’t think
    this was around in 10.3-…

Leave a reply

You must be logged in to post a comment.