UNIX File System: The UNIX File System (files and directories) are organized in a hierarchical fashion very similar to the fashion in which many corporations are organized (technically designated as a tree structure since it looks like an upside down tree). Similar files are clustered into a directory. Directories can have subdirectories etc.This is very similar to the concept of folders and sub-folders that is well understood by users of Windows95 and Macintosh systems.
At the base of this hierachy is the root directory. The root directory is designated by a single slash /. There are certain major directories which are underneath the root directory (eg. /usr, /home, /man, /tmp). These major directories contain further sub-directories (eg. /usr/bin/ is the bin sub-directory of the usr directory of root.). This structure extends further and gets complex. All subdirectories of a directory are represented by typing in the sub-directory name after the directory name separated by a slash symbol.
Example: /usr/local/bin represents the directory bin which is a subdirectory of local which is a subdirectory of usr which is a directory off root (/).
UNIX File System | File Properties | File Permissions | File Management | Directory Management

As can be seen above, the properties are divided (from left to right) Permissions, Owner, Group, Size of the File, Date of Last Modification and Name of the File. All of these properties can be modified or changed. The permissions are changed using the chmod command, the owner using the chown and the Group using the chgrp command. The file size changes when you add or remove data from the file. When you edit and save a file, its date of last modification reflects the time the change was saved. The name of the file can also be changed using the mv (move) command.
UNIX File System | File Properties | File Permissions | File Management | Directory Management
UNIX File permissions can take some getting used to since they are a bit cryptic and unlike anything that PC or Mac users would have experienced. A file or a directory can have Read, Write and Execute permissions and since UNIX is a multi-user system, a file or directory has a set of Read, Write and Execute permissions for :
These sets of file permissions are abbreviated to 3 sets of three characters R, W and X. The presence of a character implies that the permission has been turned on and the absence (dash) indicates that the permission has been turned off. The very first character in the permission's string is either a dash (meaning that it is a file) or a 'd' (meaning that it represents a directory. The next three characters rwx represent the permissions for the user, the next three characters the group and the last three others.
In the above example, the first line represents a regular file named index.html. This is a file since the first character of the permissions string is a dash (i.e. absence of any character). You will note that the next three characters are 'rw-'. This implies that the User (i.e. owner) of the file has Read and Write permissions but does not have Execute permissions. The Group and Others do not have any permissions i.e. niether can they Read, Write nor Execute the file.
The second line represents a directory named public_html. This is a directory since the first character of the permissions string is a 'd'. The Owner of the directory has Read, Write and Execute permissions. While the Group and Others have only Read and Execute permissions.
Important: Every directory requires Execute permissions otherwise it will be inaccessible.
Permissions can be given or revoked individually to each section
(User, Group or Other) or to All. The chmod
command is used for changing permissions. The format of the command
is
chmod {section}{+ | -}{permission}
filename

The section can be a for all sections, u for user, g for group and
o for others.
A plus symbol adds permissions and a minus symbol removes
permissions.
The permission can be r for read, w for write and x for execute.
|
Adding read permissions to all users |
chmod a+r public_html |
|
Removing read permissions from all users |
chmod a-r private_files |
|
Add execute permissions to a file for the user |
chmod u+x bin_file |
|
Remove write permission to a file for group members |
chmod g-w read-only-file |
|
Adding read and execute permissions to a directory to all users |
chmod a+r public_html |
The following videos will further demonstrate using the chmod command
UNIX File System | File Properties | File Permissions | File Management | Directory Management
|
Displaying the contents of a file: |
Use the cat command to display the contents of a
file to the screen. If the file is larger than a screenful,
it will scroll off the screen. |
|
Displaying the contents of a file one screenful at a time |
Use the more,
page
or less
commands to display a file to the screen, one screenful at a
time. |
|
Copying a file to another file |
Use the cp
command to copy files either within the same directory, to
another directory or from one directory to another
directory. |
|
Copying a file to another directory |
Example: cp index.html public_html/index.html |
|
Copying a file from one directory to another |
Example: cp backup_html/myfile.html public_html/myfile.html |
|
Copying an entire directory and its files to another directory |
Example: cp -r backup_html public_html |
|
Changing the name of a file |
Use the mv
command to change the name of a file. |
|
Move a file from one directory to another directory. |
Example: mv index.html public_html/index.html |
|
Move an entire directory and its files to another directory |
Example: mv -r new_html public_html |
|
Delete a file |
Use the
rm command to delete a file. |
UNIX File System | File Properties | File Permissions | File Management | Directory Management
|
Create a new directory |
Use the mkdir
command to create a new directory |
|
Delete an empty directory |
Use the rmdir
command to delete an empty directory |
|
Delete a directory and all the files it contains |
Use the rm
command with the -r option. |
|
Rename a directory |
Use the mv
command to change the name of a directory |
UNIX File System | File Properties | File Permissions | File Management | Directory Management