 |
 |
|
Overview |
 |
|
GCE |
 |
|
Marble Challenge |
 |
|
ASCIIroids |
 |
|
PSD (Second Life) |
 |
|
Gravity Bubbles |
 |
|
FractalNet |
 |
|
EcoSim |
 |
|
Cosmic Dust |
 |
|
LandMesh |
 |
|
Imagencrypter |
 |
|
Foxy Detector |
 |
|
MacDiff |
 |
|
Asteroid Belt |
 |
|
Matrix Attack |
 |
|
Solar Swarm |
 |
|
OS X Terminal |
 |
|
Tools |
 |
|
Names :-) |
|
 |
 |
 |
 |
Mac OS X Terminal guide
 |
 |
Page under construction since 16th June 2008... |
The Mac OS X Terminal is an extremely useful and powerful application, but many Mac users are
put off by the fact that all interaction takes place via typed commands due to the lack of a GUI. I
am therefore creating this guide to illustrate just how useful the Terminal can be.
If you have never used the Terminal before, then check out some of these introductory articles:
1,
2,
3. (Note that, since Mac OS X is based
on Unix, many Unix tutorial articles are also applicable to the Terminal.) The three commands which you should
learn first are:
| ls | List the contents of a directory |
| cd | Move to a different directory |
| sudo | Authenticate yourself as a superuser to gain more security privileges |
You should also learn the four special directory symbols:
| . | Current directory |
| .. | Parent directory |
| / | Root directory |
| ~ | Home directory |
It’s also useful to know that OS X stores three different timestamps for every file:
| ctime | inode change time (last change time of the file’s owner, permissions, etc) |
| atime | Access time (when the data was last accessed) |
| mtime | Modification time (when the actual contents were last modified) |
Many Terminal commands have a very large number of available options, so I will only be documenting the options which I find most useful. If you want more detailed information
about a command, consult its manual page.
Table of contents
| ls | List the contents of a directory |
| find | Search for files |
| fs_usage | Display real-time filesystem activity |
ls – View manual page
 |
 |
 |
 |
 |
 |
 |
 |
Description |
 |
 |
 |
Lists the contents of a directory. By default, it lists the contents in alphabetical order, in multiple columns.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Syntax |
 |
 |
 |
ls options
List the contents of the current directory, using the specified options.
ls options directory
List the contents of the specified directory, using the specified options. |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Options |
 |
 |
 |
The following options control the layout of the listing. Only one of these options should be used.
| -l |
List in long format. The following information is displayed for each file:
file mode, number of links, owner name,
group name, number of bytes in the file, mtime, and the filename. (Note: this option is the lowercase letter “L”.) |
| -1 |
Force output to be one entry per line. (Note: this option is the digit “one”.) |
| -m |
Stream output format – list files across the page, separated by commas. |
The following options specify how the listing is sorted.
| -S |
Sort contents by size (largest first) instead of alphabetically. |
| -t |
Sort contents by mtime (most recently modified first) instead of alphabetically. |
| -c |
When used with -l, display ctime instead of mtime. When used
with -t, sort contents by ctime (most recently changed first) instead of mtime. |
| -u |
When used with -l, display atime instead of mtime. When used
with -t, sort contents by atime (most recently accessed first) instead of mtime. |
| -r |
Reverse the order of the sort. |
Other options include:
| -h |
When used with -l, use the following suffixes for displaying file sizes: B (byte),
K (kilobyte), M (megabyte), G (gigabyte),
T (terabyte) and P (petabyte). |
| -T |
When used with -l, display complete time information for the file, including month,
day, hour, minute, second, and year. |
| -a |
Include directory entries whose names begin with a dot (.). |
| -R |
Recursively list subdirectories encountered. |
| -G |
Enable colourised output. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Examples |
 |
 |
 |
ls -l -S -h -T
List the contents of the current directory, in long format, sorted by size (largest first), and displaying suffixes for file sizes
and complete time information.
ls -1 -t -c -r -G /Users/
List the contents of the directory /Users/, with one entry per line, sorted by ctime (oldest change first),
and colourised output. |
 |
 |
 |
 |
 |
 |
 |
 |
 |
find – View manual page
 |
 |
 |
 |
 |
 |
 |
 |
Description |
 |
 |
 |
Searches in the specified root directory (including subdirectories), and lists all files which match the search criteria.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Syntax |
 |
 |
 |
find root_directory search_criteria
root_directory Files and subdirectories in this root directory will be searched.
search_criteria Only files which match all these criteria will appear in the search results.
To search in directories which require high security privileges, use:
sudo find root_directory search_criteria
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Search criteria |
 |
 |
 |
| -name pattern |
The filename must match pattern (case sensitive). This can be an exact string,
such as "readme.txt", or you can use the special wildcards, including * (matches any zero or more characters)
and ? (matches any one character). These wildcards may be matched explicitly by escaping them with \. For example,
-name "*.txt" matches all files ending in .txt, and -name "questions\?.txt" matches files
with the exact name questions?.txt. More information on patterns can be found
here and
here. |
| -iname pattern |
Like -name, but the match is case insensitive. |
| -maxdepth n |
The depth of the file into the directory tree must not be greater than n directories. For example,
-maxdepth 1 will only match files in the current directory, and -maxdepth 2 will
match files in the current directory and one level of subdirectories. |
| -size Rnc |
If R is not supplied, then the file’s size must be exactly n
bytes. If R is +, then the file’s size must be more than n
bytes. If R is -, then the file’s size must be less than n
bytes. For example, -size 1024c matches files of exactly 1024 bytes, and -size +2048c matches files
larger than 2048 bytes. |
| -newerXt timestamp |
The file must have a newer atime (X=a),
ctime (X=c) or mtime (X=m) than
timestamp. There are many valid formats for timestamp, including absolute (eg.
'22 Jun 2006 7:40pm') and relative (eg. '1 minute ago', '3 hours ago', etc). More
information on timestamp formats can be found here. |
| -type filetype |
The file must be of type filetype. The possible types include d
(directory), f (normal file) and l (symbolic link, also known as an alias or shortcut). |
Any of the above criteria can have -not added before it, to reverse the condition. For example, -not -name "*.txt" will
match all files whose names don’t end in .txt, and -not -newermt '22 Jun 2006' will match all files whose modification times
are not later than 22nd June 2006.
| -ls |
Print detailed information for each matching file. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Examples |
 |
 |
 |
find ~ -ls -iname "data*" -maxdepth 3
Search from the home directory, and print detailed information for all files whose names begin with data
(case insensitive) and are not more than 3 directories deep (including current directory).
find /Users/michaelhogg/Desktop/ -ls -newermt '22 Jun 2006' -size +1024c
Search from the directory /Users/michaelhogg/Desktop/, and print detailed information for all files which were modified after 22nd June 2006
and are at least 1024 bytes in size. |
 |
 |
 |
 |
 |
 |
 |
 |
 |
fs_usage – View manual page
| Automatic country lookup for comments powered by |
 |
 |
Comments
| No comments yet. Be the first to add a comment! |
Add a comment
|
 |
 |
 |
 |
|