Command Syntax PrimerLast updated: 08 May, 2006 This document uses DiskTester commands as examples. Any other diglloyd.com command line tool uses the same syntax. To explain the syntax of a command, special characters are used to denote usage:
Examples—required value <volume-name> Three examples are shown above. The angle brackets (<>) indicate that the item is required. The use of italic text indicates that you must enter an appropriate value, in this case the name of a volume (disk), the number of iterations, and the size, respectively. Examples—one of several possible values <start|middle|end|dd%> The angle brackets (<>) indicate that the item is required. There are 4 possible values to enter: the word “start”, the word “middle”, and the word “end”. The final choice “dd%” (with the “dd” in italic text), means that a percentage is to be entered eg “30%, “50%”, “100%”. Example—optional value [volume-name] The square brackets ([]) indicate that the value is optional. The use of italic text means that an appropriate value is to be entered, in this case the name of a volume (disk). In some cases, values may be repeated. This is denoted with the “*” character: [volume-name [volume-name]*] The line above indicate that all items are optional, but that more than one volume may be specified, separate by white space. For example: disktester show-info "Macintosh HD" Backup "RAID" Note the use of quotation marks around “Macintosh HD” above (straight quotes, not curly quotes). This is important: if the quotes are not used, then DiskTester will see the four (4) volumes named “Macintosh”, “HD”, “Backup”, and “RAID” instead of the desired “Macintosh HD”, “Backup”, and “RAID”. Example—dissecting command syntax Shown below is the command syntax as displayed by “disktester help run-area-cmd”. (Note than when in terminal, there is no italic or bold or color to the text). Note also that long option names must be specified starting with two dashes “--” and short option names must be specified using a single dash “-” eg “--chunk-size” vs “-c”. run-area-test Here is what the above syntax means:
Here are example uses of the run-area-test command, where “Speedy” is the volume name: disktester run-area-test Speedy The latter two examples are equivalent; the first one uses the full option names, and the second one uses the single-character equivalents. Shortcuts Within Terminal, there are various shortcuts you can use to reduce the amount of typing you need to do. Here are a few simple ones that work in the “bash” shell (the default for MacOS X):
Suppose you always want to use run-area-test with specific arguments. Here is how to define a shortcut: llcG5:/Applications/Utilities lloyd$ alias run-area-test="/disktester run-area-test --chunk-size 32M --test-size 1G --delta-percent 20" Now you can simply enter 'run-area-test': llcG5:/Applications/Utilities lloyd$ run-area-test X8 The 'alias' command is fairly limited, but very useful nonetheless. To see commands that you’ve previously entered, type 'history'. You can also specify the number of previous commands. For example, to see the last 30 commands you’ve entered: llcG5:/Applications/Utilities lloyd$ history 3
560 /disktester create-files -n 10 Small
561 /disktester create-files -n 10 -l verbose Small
562 /disktester create-files -n 100 -l verbose Small
You can then reference a command by number. For example, to repeat command 560, you would enter: llcG5:/Applications/Utilities lloyd$ !560 When you start Terminal, a “shell” is the program that runs within the window and accepts and executes the commands yo enter. On MacOS 10.4, the 'bash' is the default. If you are running MacOS X 10.3, you can set the default shell to bash using Terminal preferences, setting the shell to “/bin/bash”. You can define shortcuts such as 'alias' in a login file that gets read whenever you open Terminal. Create a plain-text file named “ .bash_profile” in your home directory containing all your shortcuts. The quickest way to create and edit the file is as follows: llcG5:~ lloyd$ cat > .bash_profile ^D llcG5:~ lloyd$ open .bash_profile The “^D” means to type control-D, which signals the end of input to the 'cat' command . The control key is labeled “control” on your keyboard. Following that, the 'open' command opens the (empty) file in the default text editor, typically TextEdit. Before putting commands into '.bash_profile', you might want to verify you have typed them correctly by trying them first, then copying what you typed. Shell variables [advanced topic] Shell variables allow you to place values into variables, and then use those variables wherever desired. This can be useful if you want to run a series of commands, and want to ensure that the same parameters are used for every command. In the example below, two variables are defined, 'CHUNK_SIZE' and 'TEST_SIZE', which are then used in the 'run-area-test' command. The '$' character means “substitute the value of the variable”. For example: llcG5:~ lloyd$ export CHUNK_SIZE="--chunk-size 32M" llcG5:~ lloyd$ export TEST_SIZE="--test-size 1G" llcG5:~ lloyd$ /disktester run-area-test $CHUNK_SIZE $TEST_SIZE X8 DiskTester 2.0fc2 (C) 2003-2006 diglloyd, Inc. All Rights Reserved => Allocating maximum size contiguous file on "X8" (1.01TB)... 990.2GB (95.7% of volume size) => Using test size of 1GB, 32MB at a time, across a 990.2GB test file. => Testing at: 0%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 100% Area 0% (offset 0B): writing...496MB/sec, reading...434MB/sec … addititional output not shown … How to write shell scripts is beyond the scope of this document, and indeed the author is not particularly skilled at it. However, for those more adventurous souls, an example is shown below. For your convenience, the script is in the “Extras” folder on the installation disk image. Assuming you have saved the script as “test-all.sh” in your home directory, and that DiskTester is installed in /Applications/Utilities, the following commands will execute the script (substitute the desired volume name for volume-name): llcG5:~ lloyd$ cd The example script: #/bin/sh export LOGGING="--output-level normal+log" export DT=disktester export LOG_FILE="$HOME/Library/Logs/disktester.log" echo "Verifying volume $TEST_VOL" | tee -a $LOG_FILE diskUtil verifyVolume /Volumes/$TEST_VOL | tee -a $LOG_FILE $DT;$LINE $DT help ;$LINE $DT help run-area-test;$LINE $DT help run-sequential;$LINE $DT help run-sequential-suite;$LINE $DT help run-random;$LINE $DT help test-reliability;$LINE $DT help show-info;$LINE $DT help create-files;$LINE $DT help read-files;$LINE $DT help create-hierarchy;$LINE $DT help create-hierarchy-template;$LINE $DT help help;$LINE $DT show-info $LOGGING $TEST_VOL;$LINE $DT show-info $LOGGING ;$LINE $DT run-area-test $LOGGING -c 6M -p 50 -t 128M -i 1 $TEST_VOL;$LINE $DT run-area-test $LOGGING -c 6M -p 50 -t 128M -i 3 $TEST_VOL;$LINE $DT run-area-test $LOGGING -c 6M -p 50 -t 128M -i 3 $TEST_VOL;$LINE $DT test-reliability $LOGGING --test-size 256M $TEST_VOL;$LINE $DT test-reliability $LOGGING --test-size 256M -x random $TEST_VOL;$LINE $DT test-reliability $LOGGING --test-size 256M -i 3 -x 01 $TEST_VOL;$LINE $DT run-sequential $LOGGING -c 32M -t 128M -a start -i 1 $TEST_VOL;$LINE $DT run-sequential $LOGGING -c 32M -t 128M -a middle -i 1 $TEST_VOL;$LINE $DT run-sequential $LOGGING -c 32M -t 128M -a end -i 1 $TEST_VOL;$LINE $DT run-sequential $LOGGING -c 32M -t 128M -a 20% -i 1 $TEST_VOL;$LINE $DT run-sequential $LOGGING -c 32M -t 128M -a start -i 3 $TEST_VOL;$LINE $DT run-sequential $LOGGING -c 32M -t 128M -a start -i 3 $TEST_VOL;$LINE $DT run-sequential-suite $LOGGING -t 128M -s 1M -e 8M -i 1 $TEST_VOL;$LINE $DT run-sequential-suite $LOGGING -t 128M -s 1M -e 8M -i 3 $TEST_VOL;$LINE $DT run-sequential-suite $LOGGING -t 128M -s 1M -e 8M -i 3 $TEST_VOL;$LINE $DT run-random $LOGGING -t 4G -c 32K --num-random 200 -i 1 $TEST_VOL;$LINE $DT run-random $LOGGING -t 4G -c 32K --num-random 200 -i 3 $TEST_VOL;$LINE $DT run-random $LOGGING -t 4G -c 32K --num-random 200 -i 3 $TEST_VOL;$LINE $DT run-async-test $LOGGING --duration 10S $TEST_VOL;$LINE echo "Verifying volume $TEST_VOL" | tee -a $LOG_FILE diskUtil verifyVolume /Volumes/$TEST_VOL | tee -a $LOG_FILE $DT create-hierarchy-template $LOGGING $TEST_VOL;$LINE $DT create-files $LOGGING --file-size 10M --num-files 10 $TEST_VOL;$LINE $DT create-files $LOGGING --file-size 128K --num-files 2000 $TEST_VOL;$LINE echo "Verifying volume $TEST_VOL" | tee -a $LOG_FILE diskUtil verifyVolume /Volumes/$TEST_VOL | tee -a $LOG_FILE $DT read-files $LOGGING $TEST_VOL;$LINE echo "Verifying volume $TEST_VOL" | tee -a $LOG_FILE diskUtil verifyVolume /Volumes/$TEST_VOL | tee -a $LOG_FILE echo DONE |