Miscellaneous UNIX Commands

– display online documentation (“manual pages”) for a command.


man ls
displays detailed documentation on the ls command

– list the manual pages relating to a particular keyword.


apropos file
list manual pages that mention “file” in their
summary line.

– Scan a directory structure for files matching certain criteria, and
either print their names or do nearly anything else with them. Similar to
Sherlock, but very unixlike (i.e. terse, cryptic, case sensitive, and extremely
powerful if you understand it well enough).


find / -name foo
Search the entire file structure
(including all mounted volumes) for files named exactly “foo”, and print
their paths.

Note: under some conditions (especially involving complex NetInfo networks)
this may search infinitely amongst various network volumes. Use the
-x option to avoid this (see next example).

find -x / -name foo
Search just the boot volume (the
-x prevents it from crossing to other volumes) for files named
exactly “foo”, and print their paths.
find . -name '*foo*'
Search the current directory and
all subdirectories for files whose names contain “foo”. You need to use
the quote-marks in the command, or something incomprehensible will happen.
find . -mtime -2
Search the current directory and
all subdirectories for files modified within the last 2 days. (Note: this
may also find some files with confused modification dates — i.e. files that’re
marked as having been modified in the future. -mtime -0 would find
ONLY the files with future modification dates.
find -x / -user george -print0 | xargs -0 chown eva
Search just
the boot volume for files owned by George, and assign them to Eva instead.
Note: you must be root to do this (otherwise, you’ll get a lot
of error messages).
find ~/Documents -type f -print0 | xargs -0 grep -il birthday
Search all documents (using the grep
command) in my personal Documents folder, and print a list of files containing
the string “birthday” (either upper or lowercase). (The “-type f
is there so it won’t try to search directories, or other non-document-ish things;
-i” tells grep to ignore upper/lowercase distinctions, and
-l” means print the filenames [actually paths], not the matching

– Scan a database for files with a given name, and print their names.
Faster than find, but requires that the database be built in advance
(and be up to date).


  • In order to see all files, and have permission to build the database,
    the script to build/update the database should run as root.
  • Because the database contains a complete list of files on the disk,
    (including those in private directories), and is readable by anyone, this
    can … have security implications. If it worries you, just don’t build
    the database in the first place.
  • locate’s matching rules can be rather counterintuitive, mainly because
    it searches the entire path, not just the filename, for a match to what
    you tell it to search for. Together with the fact that if your search
    string doesn’t contain any wildcards it searches as though you specified
    wildcards at the beginning and end of the search string, this means it
    may not do exactly what you expected.


sudo /usr/libexec/locate.updatedb
Switch to root (see
sudo) and build/update the database.
locate foo
Search the database for files with names
containing “foo”, or in folders with names containing “foo”, and print
their paths.
locate '*.jpg'
Search the database for files with names
ending in “.jpg” (but not in folders ending in “.jpg”), and print their

– Open a file in the GUI (essentially equivalent to double-clicking
the file in the finder).


open ~Documents/foo
Open the file “foo” in my Documents
open -a /Applications/TextEdit.app ~/Documents/foo
the application TextEdit to open “foo” (equivalent to drag-and-dropping foo
on TextEdit).

Leave a Reply