![]() |
| |||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This command changes your current working directory. Just give it the pathname of the directory you wish to move to. The pathname can be either absolute or relative. For example: % cd /Users will set the current working directory to the Users directory just above your home directory. Confirm this with: % pwd To get back to your home directory, type either of: % cd /Users/your-home
The '~' or tilde character is shorthand for your home directory. Typing just 'cd' will also get back to your home directory. This works on the default Mac OS X set-up, but not universally. To move to the Documents directory within your home, follow the above command with: % cd Documents 'Documents' is a relative pathname and assumes your current working directory is (soon to become 'was') your home. % cd /Users/your-home/Documents will do the same using absolute pathnames. You will be aware of the Finder's ability to show file information like size, date of change, and permissions. Well, 'ls' can do all that too. We have to specify options to tell 'ls' how to behave.
Try: % ls -l on a number of different directories. '-l' means 'long', and tells 'ls' to output additional information. As an example of the information output: -rw-r--r-- 1 melkor staff 17181 Apr 23 20:04 ipfw.txt shows a file 'ipfw.txt', and a directory 'Public'. Considering 'ipfw.txt' in more detail: -rw-r--r-- The initial '-' indicates that 'ipfw.txt' is a file, directories have 'd'. The next nine characters give the permissions - who can read, write, and execute the file, in the order user, group, and others. We will discuss permissions in more detail in a later column. (Also see the Advanced Unix Lesson.) '1' is the number of links (ignore this). melkor staff gives the user who owns the file, and the group which owns the file. The next fields are the file size in bytes, the date and time of last modification, and finally the filename itself. Note that the size of a directory does not include the total size of all files within the directory. The option '-t' sorts by time modified (most recently modified first) before sorting the operands by lexicographical order. And finally, '-lt' does both. Of immense use is auto completion. By hitting the tab key as you are partway through typing a pathname or file name, one of three things will happen:
Try: % ls /U Auto completion also works when you are partway through typing a command. |
Tell Me More... |
|
Tilde On my (UK) keyboard, the '~' character is just to the left of 'Z'. It is equivalent to: /Users/your-home and is an absolute pathname. It can be used with all commands, for example: % ls ~ will list your home directory. Command Operands One can supply additional information to Unix commands. 'ls' can take a directory to list. Each piece of additional information is termed an operand. Command Options Options are like operands except they change the default way in which a command operates. They are (usually) placed before operands and are distinguished by a preceding '-'. Options are one letter long, and case is important. '-a' is different to '-A'. To save typing, multiple options may be merged, and preceded by a single '-'. For example, the following are equivalent. % ls -a -l -t Finally, '-h' is often the help option. Try: ls -h Ok, so not that helpful :-) 'man' - Tell Me More 'man' is a very useful command. It calls upon the Unix manual pages. So: % man ls will tell you all about 'ls'. You can't do much harm with 'ls', so read the manual and have a play. 'man' is very much a reference, not a tutorial - as you are about to find out. :-) Hit the 'return' key to scroll down a line at a time, or 'space' to scroll down a page at a time. Hit 'q' to quit out of the manual. |
In Part Two
In the next part to this column I will cover more useful Unix commands that allow you to create and delete files and directories.
In the meantime, try the following commands:
% cd ~
% ls ..
% ls .
% ls -al
When you wish to finish working at the command line close the Terminal window by typing:
% logout
Enjoy :-)
Discuss this article in the Learning Center forum
|
|
Part 1 - Lose the Mouse (page 2 of 2) |
|