Moving Around in the File System

Moving Around in the File System

When using Unix, you will frequently want to change your working directory because the current directory is the default location for many commands (the terms current directory and working directory are used interchangeably in Unix documentation, as discussed above in "Seeing Where You Are in the File System"). For example, the ls command lists the contents of the current directory if given no arguments. If you never changed your working directory, you would often need to type very long paths and would be more likely to make mistakes.

To change your working directory:

  • cd Public

    The cd command takes either no arguments or one argument and produces no output (unless it fails to work; remember that in Unix, "Silence means success"). The argument to cd is the path of a directory that will become your new working directory (in this case, Public ). If you do not supply an argument, cd takes you to your home directory. You can see where you are with pwd .

    Notice how your shell prompt changes to reflect your new working directory. Figure 5.12 shows the shell prompt before and after the cd command. See the sidebar "A Special Name for Home" for an explanation of the ~ (tilde) character.

    Figure 5.12. Using cd to change your current directory. Your prompt also changes.
     localhost:~ vanilla$  cd Public  localhost:~/Public vanilla$ 

    In this example, Public is a relative path , but quite often you will use a full path :

  • cd /etc/httpd

    takes you to /etc/httpd regardless of where you were.

Tip

  • You can use the special directory name .. with the cd command:

    cd .. /..


To move back to your home directory:

  • cd

    If you use the cd command with no arguments, it will take you back to your home directory.

Filenames Are Case Sensitive

Unix systems, including Darwin, use case-sensitive filenames. So at the command line, a file or directory named Public is not the same as one named public .

Your Mac uses a format for its disks called the Mac OS Extended (or HFS Plus) file system. The Mac OS Extended format is a "case- preserving , case-insensitive" file system. Apple has done a very nice job of dealing with this in Mac OS X.

If you are working at the command line on a Mac OS Extended partition (Mac OS Extended format is the normal way a Mac OS X partition will be formatted), then file and directory names are case insensitive. It is possible to format a disk using a case-sensitive version of the Mac OS Extended format, but this is not recommended; see "Mac OS X 10.3: The Dangers of Case-Sensitive HFS+" (www. macfixit .com/staticpages/index.php?page=2003111009264885) for a discussion of the issues.

If you are working in a UFS partition (a common way of formatting in the Unix world), then file and directory names are case sensitive, and if you look at a UFS folder from the Finder, you will see that you can have two files whose names differ only in casefor example, FOO and foo.




Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net