What is a Unix command?
If you're new here, you may want to subscribe to my RSS feed.
A Unix command is like an application, but it usually performs a much simpler task. There are Unix commands to show the contents of a file, to sort, to filter, and even to browse the Internet. Every Apple computer comes with hundreds of Unix commands that each do something unique. Contrast that with the dozens of applications that come with every Mac, some of which perform very complicated workflows.
Mac applications have Preferences for selecting how you’d like them to run. Unix commands, on the other hand, don’t (usually*) have any preferences or persistent settings. To specify how a Unix command runs, you use what are called flags or arguments. These flags or arguments are specified each time you run the command.
Arguments are specified with one dash and a letter (e.g. -a -b -c), or two dashes and a word (--help.) Sometimes certain settings or parameters can follow an argument (-u "stevejobs" or --user "stevejobs".) Whenever you use multiple single-letter parameters, you can combine them (-abc is the same as -a -b -c.)
Here’s an example. The ls command lists the files in a folder. Open Terminal, type ls, and hit Enter. You’ll see a list of the files and folders in your Home folder. Each name is listed one after another.
If, instead, you’d like to see all the files listed in columns, type ls -l and his Enter. You’ll see all the files listed in one column. It will also show the dates the files were created, and other information. This is the “long” format, as specified by the l flag.
You’ll notice that the list of files is in alphabetical order. If you want to reverse it, you can use the r flag. Type ls -l -r. The files will be listed in reverse alphabetical order. Since you can combine single letter flags, ls -lr will produce the same result. Most of the time the order of the flags doesn’t matter either, so ls -rl also produces the same result.


September 16th, 2006 at 9:21 am
cool
October 3rd, 2006 at 9:30 am
[…] When discussing what a Unix command is, I mentioned that you can alter the function of a Unix command by using flags or arguments. For example, to list all the files in your current folder, you use the ls command. To reverse its order you add the “r” argument: ls -r. But how do you know which arguments to use? […]