Tutorial
Unix
Files and Directories
Unix
File and Directory Names
/, rather than \ for path separator, so it's home/weiss, NOT \home\weiss
? matches any single character — program_?.cpp matches program_1,
program_a, program_!,
* matches any sequence of characters — program_*.cpp matches program_1.cpp,
program_original.cpp, program_.cpp
$HOME, ~ - your home directory
~username - username's home directory
. - current directory
.. - parent directory
Absolute and Relative Paths
- A file's path is the set of directories leading from the topmost directory to the one containing the file itself. Thus if the file is
/home/weiss/private/Programs/Lecture01/hello.cpp, then the file (hello.cpp) has the path
/home/weiss/private/Programs/Lecture01.
- Paths may be specified in an absolute by specifying the full sequence from the topmost
(root) directory. This is done by beginning the path with a
/. This is known as an
absolute path. Thus, the absolute path /home/weiss/public_html refers to starting at the topmost
directory, moving into the home directory; from there moving to the weiss directroy and finally to the
public_html directory.
- In the second method of specifying directories, paths are specified relative to the current directory, i.e.,
the directory you are currently in. Such relative paths do no begin with a
/ and
their startiing location is the current directory. Thus, the path Programs/Lecture02 means than one move from the current directory to
the directory named Programs and from there to the Lecture02. Furthermore, if our current directory were
/home/weiss/private then the absolute path of the above would be /home/weiss/private/Programs/Lecture02.
- Relative paths often make use of the
.. symbol for the parent directory (which is in some respects, itself
a relative path) — it allows one to move up the directory structure (without having to know the actual name of the
parent directory). Thus if the current directory is /home/weiss/private then the path ../../arnow/public_html
(up a directory -- to /home/weiss, up a second directory -- to /home; then down to /home/arnow,
and down again to /home/arnow/public_html.
- Finally, the
~ and ~username notations allow one to begin relative paths at one's own home directory or another user's.
Working with Directories
cd dirname - changes current directory to dirname
cd - changes current directory to your home directory
mkdir dirname - creates directory dirname
rmdir dirname - deletes directory dirname (must be empty)