Introduction to Unix File System
Unix File System can be defined as a framework that organizes and stores a huge volume of data that can be handled with ease. It involves elements like file which is a collection of related data that can be viewed logically, appears as a stream of bytes, with attributes containing information in relation to the concerned file. The file system consisting of two main components i.e files, directories. The entire system following a hierarchy in which directories act as special files that contain multiple files with the highest-level directory in the entire hierarchical structure being termed as root which is symbolically denoted by ‘/’. There can be many subdirectories under this directory.
The Unix Filesystem usually has below directories present in the file system.
- bin: It is a short form for binary files. This directory stores the commonly used executable commands.
- mnt: This contains information regarding the mounted devices.
- root: This is the root user’s home directory.
- tmp: This is a storage for temporary files. As they are temporary they are removed periodically from the filesystem.
- usr: It contains a set of executable commands
- home: It has a collection of directories and files.
- proc: It contains files that are related to system processes.
What is Unix?
Unix is an operating system which has been applied to the family of multitasking, multiuser computer operating system. It was derived from AT&T UNIX operating system and was developed in the 1970s at the Bell Labs research center. It was first programmed in assembly language and again reprogrammed in C. It is stable and also provides a graphical user interface which helps in providing an easy to use environment. Unix provides users with different program development tools, electronic communication facilities and also many development tools. With these, it also provides multiple UNIX shells where one interprets your commands and those are passed to the operating system. It also has a kernel which acts as a mediator between the shell and the hardware. Kernels are relatively small and efficient. Unix also provides a separate file system where many functions can be performed. Let us have a look at the file system.
Types of Unix File System
The Unix File System consists of different types of files. Let us have a look at these.
1. Ordinary Files
These files are used to store information of the users. It may be some text or any image which is stored. It is normally located under a directory and does not contain any other files.
Directories help in organizing the files which are present. The directories can contain ordinary files, special files or even other directories. All these directories are the descendants of the root directory.
3. Special Files
The special files are used to represent physical devices like printer, tape driver or a terminal. Unix considers any device to be a file. Even the terminal is considered to be a file. It is considered as standard input file from where input is read. This terminal is also the standard output file which is the command’s output.
To link commands Unix provides pipes. The pipe is a temporary file. This also holds data from one command which is kept until it is read by another command. The output of one command is given to the next command as an input.
File Descriptor and Inode
There is clear segregation between the contents of the file and the information which is present in the file. All files consist of a sequence of characters except for the device and special files. The information which is needed in the filesystem to handle the files is included in a data structure which is called inode. The inode is used to identify a file. A few attributes must be provided to handle the kernel and filesystem functions. To name a few the attributes are file type, device id, user id of file owner, access rights and file mode, etc.
Additional File Attributes in Unix File System
A file can have some additional attributes as below.
- Permission modes: It tells the permissions which are assigned to a file for the owner.
- Owner: This is the owner of the file.
- Group: This specifies the groups associated with that file.
- File Name: It is the name associated with the file.
- Modification date: it was the date when the file was last modified.
- Size: The size of a file in bytes is specified.
- Number of links: The files which relate to a particular file.
File and Directory Commands in Unix File System
There are many commands which are provided by UNIX which help in working with files. A few of these commands are listed below.
1. ls: It lists all files in a particular directory.
It has a few variations below.
- ls dir: Shows the contents present in a directory.
- ls a: It shows all files including the hidden files.
- ls -al: It gives a detailed listing of all contents of the file.
2. Less: It displays less number of lines rather than the complete file.
3. Head: It displays the first few lines or n lines of the file.
4. Tail: Displays the last few lines or n lines of the file.
5. Cat: It displays the contents of the entire file without the pagination of the file.
6. cp: It copies the contents of one file to another. It overwrites the contents of the file if not mentioned otherwise.
7. mv: It moves the specified files to the specified destination.
8. rm: Removes or deletes the specified files.
Unix is an operating system that handles files in an organized way. With all the commands and functions managing files is very easy. It also has permissions that limit access to the files. Only authorized people can access the files and perform different operations. It also has different kinds of files segregated which makes it easier to use. The file system of Unix is hence considered to be one of the most user-friendly file systems.
This has been a guide to Unix File System. Here we discuss its file attributes along with file descriptor and Inode. You can also go through our other suggested articles to learn more –