Next Previous Contents

4. Using Directories

4.1 Directories: Preliminary Notions

We have seen the differences between files under DOS and Linux. As for directories, under DOS the root directory is \, under Linux / is. Similarly, nested directories are separated by \ under DOS, by / under Linux. Example of file paths:

DOS:    C:\PAPERS\GEOLOGY\MID_EOC.TEX
Linux:  /home/guido/papers/geology/middle_eocene.tex

As usual, .. is the parent directory and . is the current directory. Remember that the system won't let you cd, rd, or md everywhere you want. Each user starts from his or her own directory called 'home', given by the system administrator; for instance, on my PC my home dir is /home/guido.

4.2 Directories Permissions

Directories, too, have permissions. What we have seen in Section Permissions and Ownership applies to directories as well (user, group, and other). For a directory, rx means you can cd to that directory, and w means that you can delete a file in the directory (according to the file's permissions, of course), or the directory itself.

For example, to prevent other users from snooping in /home/guido/text:

$ chmod o-rwx /home/guido/text

4.3 Directories: Translating Commands

DIR:            ls, find, du
CD:             cd, pwd
MD:             mkdir
RD:             rmdir
DELTREE:        rm -R
MOVE:           mv

Examples

DOS                                     Linux
---------------------------------------------------------------------

C:\GUIDO>DIR                            $ ls
C:\GUIDO>DIR FILE.TXT                   $ ls file.txt
C:\GUIDO>DIR *.H *.C                    $ ls *.h *.c
C:\GUIDO>DIR/P                          $ ls | more
C:\GUIDO>DIR/A                          $ ls -l
C:\GUIDO>DIR *.TMP /S                   $ find / -name "*.tmp"
C:\GUIDO>CD                             $ pwd
        n/a - see note                  $ cd
        ditto                           $ cd ~
        ditto                           $ cd ~/temp
C:\GUIDO>CD \OTHER                      $ cd /other
C:\GUIDO>CD ..\TEMP\TRASH               $ cd ../temp/trash
C:\GUIDO>MD NEWPROGS                    $ mkdir newprogs
C:\GUIDO>MOVE PROG ..                   $ mv prog ..
C:\GUIDO>MD \PROGS\TURBO                $ mkdir /progs/turbo
C:\GUIDO>DELTREE TEMP\TRASH             $ rm -R temp/trash
C:\GUIDO>RD NEWPROGS                    $ rmdir newprogs
C:\GUIDO>RD \PROGS\TURBO                $ rmdir /progs/turbo

Notes:

  1. when using rmdir, the directory to remove must be empty. To delete a directory and all of its contents, use rm -R (at your own risk).
  2. the character '~' is a shortcut for the name of your home directory. The commands cd or cd ~ will take you to your home directory from wherever you are; the command cd ~/tmp will take you to /home/your_home/tmp.
  3. cd - ``undoes'' the last cd.


Next Previous Contents