- Ordinary
- Directory
- Special Files
Directories contain information the system needs to access all types of files, but they do not contain the actual data. Each directory entry represents either a file or a subdirectory. A directory is a unique type of file that contains only the information needed to access files or other directories. As a result, a directory occupies less space than other types of files. Directories enable you to group together related files and directories. Each directory entry contains a file or subdirectory name and its associated i-node number. When a user executes a command to access a file, they will use the file name. The system then matches the file name with the corresponding i-node number. Once the i-node number is known, the system will access an i-node table, which holds information about the characteristics of the file. Examples of what is stored in the i-node table include the user ID of the owner of the file, the type of file, the date the file was last accessed and last modified, the size of the file and the location of the file. Once the system knows the location of the file, the actual data can be located.
Special files usually represent devices used by the system.
Hierarchial FileSystem Structure
The / (root) directory contains many directories that are critical in the operations of the system such as:
• /sbin - System utilities for system startup
• /dev - Special files that represent devices
• /etc - System configuration files used by system administrators
The /usr directory contains system programs such as:
• /usr/bin - User commands such as ls, cat, date
The /home directory contains user login directories and files.
The /var directory contains files that dynamically change.
The /tmp directory will hold files that are temporarily needed or created by applications and programs.
Note that it is also possible to access files on another computer in the network. Several facilities are available to do this, most notably, the Network File System (NFS). From a user's perspective, remote files will appear to behave just like local files.
- The contents of the /usr directory is for commands and utilities. Users do not have write access to this directory. Since these files are usually system-related, they don't change very much.
- The /home directory is for user directories and files. Each user has a subdirectory whose name is the same as the login name. Users change their files regularly, therefore, this directory is very dynamic.
- The /tmp directory is used by applications as a work space. For example, vi uses this area as a buffer space until the file is written to disk. Compilers will write files that are used during a compilation and when the compiler is finished the files are removed.
- The /var directory is used for many user-type programs such as mail and printing. The name of the directory is short for variable since the data in this directory dynamically changes due to system activity.
Path Names
The pathname is written as a string of names separated by forward slashes (not back slashes like in DOS or OS/2). The right-most name can be any type of file. The other names must be directories.
A pathname is always considered to be relative UNLESS it begins with a slash. An absolute pathname or full pathname always starts with a slash.
Present Working Directory
The pwd command will always return the full pathname of your (current) present working directory. It is not a bad idea to use this command often, especially when you are removing files (to be sure that you are removing them from the correct directory).
Listing Directories
The ls command is used to list the contents of a directory, and has many useful options with it. If no file or directory name is specified as an argument to the ls command, the current directory will be used.
By default, the ls command displays the information in alphabetic order. When the ls command is executed it does not display any file names that begin with a dot ( . ), unless the -a option is used (as can be seen on the visual). These files are generally referred to as hidden files, for this reason.
To list all the subdirectories as well, the -R option can be used.
Ex: ls -l - Lists directories and files in long format
O/P of above commands will have several fields and they are explained below
• Field 1 shows the file/directory and permission bits. File and directory permissions will be covered in more detail in a later unit.
• Field 2 is the link count. Links will be covered in more detail in the next unit.
• Field 3 shows the user name of the person who owns the entry.
• Field 4 shows name of the group for which group protection privileges are in effect.
• Field 5 shows the character count of the entry.
• Field 2 is the link count. Links will be covered in more detail in the next unit.
• Field 3 shows the user name of the person who owns the entry.
• Field 4 shows name of the group for which group protection privileges are in effect.
• Field 5 shows the character count of the entry.
• Field 6 shows the date the contents of the file or directory was last modified.
• Field 7 shows the name of the file/directory.
• Field 7 shows the name of the file/directory.
The -i option used with the ls command displays the i-node number in the first column. The ls command is merely displaying file and directory information from the i-node table. Only the last column, the name, comes from the directory itself. Note the size of the directories in the above example. Directory space is allocated in
512-byte increments and grows in 512-byte increments.
Changing Current Directory
Using the cd command with nothing after it will automatically return you to your home directory. This is the directory into which you are usually placed when you log in.
Ex: $ cd
Creating & Removing Directories
The mkdir command creates one or more new directories specified by the dir_name parameter. Each new directory contains the standard entries . (dot) and .. (dot dot).
The rmdir command deletes the directory. The directory must be empty and you should not be inside that directory when you give rm command. The way a directory structure is removed is to first empty out each directory, then remove the directory. Also you can not be in the directory that you are trying to remove. This makes sense because if the system did allow you to remove a directory you were in, what would you be left in after the directory had gone? Tell the students to always think of the following “You can not remove the ground that you are standing on!”
The -m option can be used with the mkdir command to specify the directory being created
with a particular set of permissions.
Ex: $ mkdir /home/user1/newdir
$ rmdir /home/user1/dir2 - deletes dir
Using the -p option with the mkdir command allows you to create multiple subdirectories simultaneously. If dir1 and dir2 already exist, then dir3 will be created.
The -p option used with rmdir first removes the dir3 directory, then the dir2 directory, and finally the dir1 directory. If a directory is not empty or you do not have write permission to it when it is removed, the command terminates.
Ex: mkdir -p dir1/dir2/dir3 - creates multiple directories
The -p option with the mkdir or rmdir commands allow you to create and remove multiple subdirectories simultaneously. Not all versions of UNIX allow this syntax. The -p option can be considered to mean parent or path.
Displaying Directory Information
The -i option displays the i-node number in the first column. The -d option used with ls will list the i-node information for a directory.
The ls command has options that can display each of the timestamps:
• To display the updated time: ls -lc
• To display the modification time: ls -l
• To display the access time: ls -lu
istat displays the i-node information for a particular file or directory. AIX systems maintain three timestamps for files and directories. The difference between an update and a modification is updated changes the i-node information; whereas, a modification changes the contents of the file or directory itself. The access time is the last time the file was read or written. Reading a file changes its access time, but not its updated time or modification time, because information about the file or directory was not changed.
In AIX a file is a file is a file. A directory is a file. That is why the istat and ls commands can be used to display the information about directories as well as files. As you already know the ls command displays the contents of each specified file parameter. Using ls without any parameters displays the contents of the current directory. The -i option displays the i-node number in the first column of the report. The -d option displays only the information for the directory. Directories are treated like files, which is helpful when using the -l option to get the status of a directory. The istat output gives you additional information about the file or directory in the form of three timestamps. Updated and modification differ in that updated is like changing the wrapping paper on a gift; whereas, modification is like changing the gift that is inside the box. Useful boardwork to show difference is: chmod 755 mydir is an update. Doing a echo date >> myfile is a modification. Updated always refers to the i-node information. Modification refers to the contents of the file or directory. Access time changes anytime the file or directory is read or written. The key here is “read”. If a user or an application reads the contents of the directory, the access time changes. Neither the updated nor modification times change.
Additional Information — Only root can execute the istat command using the i-node number and device rather than a file or directory name. The same information is displayed plus the hexadecimal block pointers. These numbers are addresses of the disk blocks that make up the file or directory.
Remember that AIX has no notion of file name extensions as you have in other operating systems (such as DOS). The dot is simply used as part of the file name.
Touch Command
The touch command serves two purposes. If the file specified by the file name does not exist, a zero-length (empty) file is created. If the file does exist, the last modification time (displayed with ls -l) is updated to reflect the current date and time. If you do not specify a time variable with the touch command the current date and time will be used.
touch can also be helpful when used in situations where an application checks a file's last modification time before taking some action such as backup or compile.
Ex: $ touch file1 - will create zero length file in the current directory
0 Comment to "AIX Directory and Filesystem Structure"
Post a Comment