file system basics
This subchapter looks at the basics of the file system on UNIX or Linux.
By 1971, many fundamentally important aspects of UNIX were already in place, including file ownership and file access permissions.
graphics example
In a graphic user interface, you can see the file system directory structure in some kind of picture version. This varies by system.
The following example is from Mac OS X. If you use Mac OS X, the UNIX directories are kept hidden in Finder. You can see them by using Finders Go menu, Go To Folder
, and type private.
The following example is from Linux.
Do not mess with your system files until you know what you are doing. You can cause your computer to stop working.
Some of the typical UNIX/Linux directories are etc, tmp, var, bin, sbin, dev, boot, or home.
some basics
Both UNIX and Linux organize the entire file system into a single collection (called the directory tree). This is in sharp contrast to Windows dividing the file system into multiple parts, each based on a particular drive or device.
File names are case sensitive. The file names File and file are different files. This is in sharp contrast with Windows and Macintosh (where they are alternate names for the same file). Note that this is a Mac OS X variation from the standard UNIX practice.
A file name that starts with a period is a hidden file. In Mac OS X, you can toggle between showing and hiding hidden files in Finder by typing Command-Shift-Period.
Neither UNIX nor Linux enforce or recognize file extensions (such as .txt). In some operating systems (such as Windows and traditional Macintosh), the file extensions are recognized by the operating system and are used for such purposes as deciding which program is used to open the file. You can add file extensions UNIX or Linux file names (and this is commonly done to help humans organize their files), but the file extension is ignored by the operating system and has no special meaning.
Most modern Linux and UNIX operating systems support long file names with a wide variety of characters, including the space character. Shells are set up for old school UNIX, which had a limited number of characters in file names and a very limited choice of characters in file names. it is best to use these old school limits for files you manipulate through the UNIX or Linux shell. Mac OS X allows you to put file names inside quotation marks (to allow such things as spaces in file names). You can also access files through their inode numbers (which will let the shell work on any file name). Still, it is wise to use only letters, numbers, period, hyphen, and underscore in UNIX or Linux file names 9and particularly to avoid the space character).
directory tree
A directory in UNIX or Linux is the same as a folder in Macintosh or Windows.
Directories may contain any combination of files and subordinate directories.
This structure is called a tree. It branches out from a root.
The root is the beginning of the filesystem.
A branch is a directory and all of its subdirectories.
When a directory is inside another directory, the one inside is called a child and the outer one is the parent.
A leaf is anything that has no children, such as a file.
Unix and Linux are organized into a single file system tree, under a master directory called root and designated by the forward leaning slash ( / ). This is in sharp contrast with Windows, where there is a seperate file system tree for each drive letter.
In UNIX, everything is is a file. Even a directory is just a special file that stores information about other files.
some important directories
The following is a brief description of some of the major directories. Not all systems will have all of these directories.
/ The root directory of the entire file system.
/bin A collection of binary files, better known as programs.
/boot or /kernel The files needed to boot or start your computer.
/dev The devices connected to your computer (remember, everything, even hardware devices, is treated as a file in UNIX or Linux).
/etc System configuration files, startup procedures, and shutdown procedures.
/home or /users The home directories for each user.
/lib or /Library Library files.
/net Other networked systems (again, treated as files).
/opt Third party software. In older systems this might be /usr/local
/private On Mac OS X, this is the location of the UNIX files. It is normally kept hidden from all users in Finder, but is visible in your terminal emulator and shell. Mac OS X has links to the major UNIX directories at the root level so that UNIX and Linux tools can find their files in the standard locations.
/proc Information about processes and devices.
/sbin System binaries (that is, system programs).
/tmp Space for temporary files. Required by all forms of UNIX.
/usr User binaries (programs), libraries, manuals, and docs.
/var Variable files.
Swap Virtual memory on a hard drive. Allows the memory manager to swap some data and program segments to hard drive to expand the amount of memory available beyond the limits of physical memory.
For a more advanced and complete listing, see major directories.
home and working directory
The home directory is the directory that your system places you in when you first log into your system (start the shell). The home directory is defined in the /etc/passwd file. This is your personal space on a UNIX or Linux machine.
The tilde character can be used to name your home directory. ~user-name (where user-name is your actual user name) indicates your home directory.
The working directory is whatever directory you happen to be working in. The working directory is always the same as the home directory when you start a shell session, but you can change your working directory at any time (and typically do change it). Commands normally are applied to the current working directory.
The working directory may also be called the current directory, current working directory, or present working directory.
parent and child directory
Any directories underneath a particular directory are called child directories. Any directory can have zero, one, or many child directories.
The directory above any particular directory is called the parent directory. Any directory has only one parent (with the exception of root, which has no parent).
absolute paths
Every directory or file can be defined by a complete absolute path. The complete absolute path gives every level of directory, starting from the root. An absolute path name is sometimes called the full path name.
An example might be the /usr/java/bin. This would be a directory containing Java binaries. In this example, under the / root directory there is a directory called usr and inside that directory there is a directory called java and inside that directory there is a directory called bin and inside that directory there are programs for running Java.
Absolute paths normally start at the root of the file system.
relative paths
Relative paths describe where to find a file or directory from the current working directory.
A single period (or dot) character ( ./ ) indicates that you are describing the path to a directory or file from the current working directory.
If your current working directory is www and that directory is under /usr, then the file index.html inside the current working directory can be described by the full or absolute path of /usr/www/index.html or a relative path name of ./index.html.
The single period is called dot.
Two periods ( ../ called dot dot) take you up one directory to the parent directory.
You can use a series of two dots ( ../../ ) to go up more than one directory level.
dots and tildes and slashes
/ Slash is used as a separator between directory names. When slash is the first character in a path name, it indicates the root directory.
~ Tilde is used to get to your home directory.
./ Single dot is used to indicate the current working directory.
../ Two dots are used to indicate the parent of the current working directory.
. A single dot in front of a file name (such as .Trash) is used to make a hidden file. Hidden files are only listed when specifically requested.
hidden files
A file name that starts with a period is a hidden file. In Mac OS X, you can toggle between showing and hiding hidden files in Finder by typing Command-Shift-Period. In MS-DOS, a hidden file cant be written to. In UNIX and Linux a hidden file can be read and written.
Some important hidden files are the files used to configure the working environment, including .cshrc, .login, and .profile.
Some programs keep application-specific resources in hidden files or hidden directories.
moving around
This will all make a bit more sense in the next subchapter as you learn how to actually move around your file system.
comments, suggestions, corrections, criticisms
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.