Files, Directories, and Paths
Directories
- LINUX uses directories, similar to Windows folders, to organize files.
-
Directories can be created with the mkdir command,
and removed with the rmdir command.
-
Directories can contain files and other directories (called subdirectories).
- A directory is also a file; it's a special file that can contain other files.
-
Directories have the same naming rules as files. Although it is possible to
use other characters in your file names, you should stick with a thru z,
A thru Z, 0 thru 9, _ (underscore), and . (dot).
- Files that begin with a . (dot) are called hidden files, and will not be visible when using the ls command unless a specific flag is used. (You should all go read the man page for ls and find the flag. Send us an email if you get it.)
- LINUX does not have a concept of directory/filename suffixes; it is just considered part of the name. For instance, you can add a .txt extension to any file (or directory), but is does not tell LINUX that it is a text file, like a Windows extension does.
Directory System Structure
- The UNIX filesystem is hierarchical, which means that all directories and
files are organized in a tree-like structure with the directories corresponding
to branches and files corresponding to leaves.
-
The topmost directory is called the root directory or
slash, and is notated as simply /
- Since directories are located "under" the root directory,
it can be said that every directory on a UNIX machine is a subdirectory except
for the root directory.
Note - don't confuse the root directory with the root
login or user. The root directory is simply the topmost directory in the LINUX
filesystem. The root login is a user on the LINUX machine who has absolute
power to do anything on the machine.
- The directory you are currently in is called your current
directory or working directory. When you first
log in, your working directory is your home directory (more on that soon!).
Absolute and Relative Path Names
- Every directory (or file) has a full name, called an absolute or fully qualified pathname.
- An absolute pathname uniquely identifies a specific directory (or file) on the LINUX machine.
- And absolute pathname always starts with a slash (/), followed by any subdirectories in its path separated by slashes, and ending with the name of the directory (or file).
- For example, /Users/cathybishop/g/bin/readme.txt is an absolute path for some kind of a
file (we can't tell exactly what by the name) called readme.txt in the bin subdirectory of the cathybishop subdirectory of the Users subdirectory of /.
- If my current directory is /Users/cathybishop/g and I type ls -ld /tmp, then I will see the long listing of the directory named /tmp. However, if I type ls -ld tmp, I will see the long listing of the directory named /User/cathybishop/tmp because this is a relative pathname (keep reading!)
- Directories (and files) can also be referred to be relative pathnames. Relative means the pathname is relative to your current directory.
- For example, a file with an absolute pathname of /Users/cathybishop/g/my_dogs can be referred as simply my_dogs if my current directory is /Users/cathybishop/g.
- If my current directory is /Users, then I can reference the my_dogs file in one of 3 ways:
- I can cd to the /Users/cathybishop/g directory and then reference the file as simply my_dogs (for example, file my_dogs)
- I can use the absolute pathname of the my_dogs file (i.e. file /Users/cathybishop/g/my_dogs)
- I can use a relative pathname (i.e. file cathybishop/my_dogs or file ./cathybishop/my_dogs).