File System in Linux
We always keep hearing and speaking about file of different kinds like text file, word file, video file, audio file, image file etc But do you know that everything in Linux is a file? Understanding a file system is necessary part of Linux which we are going to discuss here.
What is the file?
File is nothing but linear stream or a small block of byte. User can read, write or execute the file. Linux system is used for multiuser purpose so each user can access the file and modify it. The administrator can also set the permission so that noone can modify it without his/her permission. User can be classified in three categories:
User – Owner of the file who generates the file.
Group – Group of users for specific file
Another- Another person who can access the file after administrator’s permission.
Total nine permission bits are associated with single file. Each of the three bits is associated with all three categories.
– |
r |
w |
x |
r |
w |
x |
r |
w |
x |
Here, (-) dash is an indication of regular file. The symbol ‘r’ is for read, ‘w’ is for write and ‘x’ is for execute. Each group of rwx is associated with user, group and another category respectively. System doesn’t understand the file name, it just understands digital value. When file is created by a user or group of users, it is stored as a numerical value in system called User ID Group ID.
Suppose I have created the file named as engineersgarage.txt by touch command:
touch engineersgarage.txt
Now, enter the following command:
ls -l engineersgarage.txt
The following output is displayed on terminal:
-rw-rw-r– 1 ashish ashish 0 Mar 1 10:12 engineersgarage.txt
Here, you can show how to assign permission to the file. First and second combinations of three bit rw- are associated with user and group respectively. It provides read and write permission to user. Last combination of three bit r– is associated with another group which only reads the file.
What is Directory
A folder in Windows is called a directory in Linux. It’s a special file which associates file names with specific collection or group of files. You can store various files in a single directory. File name contains only valid 8 bit expect Null and forward slash (/) while Directory is a collection of metadata information called inode that contains all the information expect file data. It contains type, owner, permission, modification, time, location of file data, etc also known as metadata.
User can read, write or execute permission with directory but not like file. Read permission is associated with search in directory which is contained by the file. Write permission allows removing or creating file in directory and execute permission lets you go through directory while it’s open.
Executable File
In Linux, there are 2 kinds of information- instruction (code) and useful data, whereby the former is called binary object file. Compiler compiles the file and creates object file which is linked with library file and creates executable file. When you create executable file, by default it is generated as a.out file. Refer to the tutorial How to make first C programming in Linux for understanding how to execute file.
Linux File System
Linux File System
Everything in Linux is a file. Kernel is a collection of files which are written in C language as well as assembly language. File system is hierarchical structure in Linux which has a different meaning associated with each inode. It is standard tree hierarchical structure comprising various meaningful directories and files. One special directory file which has the permission to do everything is called root directory. Root is main directory in Linux file system and is indicated as forward slash ( / ). User ID of root is zero in system. Each and every directory is associated under the root.
One of the most important features of Linux is that it supports various file systems types like ext, ext2, xia, minix, umsdos, msdos, vfat, proc, smb, ncp, iso9660, sysv, hpfs, affs etc. which ensures flexibility.
When the disk is initialized and partitioned in logical block, each partitioned structure contains one type of file system like ext2. File systems arrange files into logical hierarchical structures with directories, soft links and so on held in blocks on physical devices. Devices that contain file systems are known as block devices. EXT2 stand for second extended file system while EXT3 is animproved version of EXT2 file system. Each file system has different characteristic and performance.
Various directories are located under the root directory in Linux file system. If you want to see all directories present in Linux file system, check once you are in root.
Enter the following command to see hierarchical structure of file system:
$ ls
The following output is displayed on terminal:
bin cdrom etc lost+found mnt proc run srv tmp var
boot dev home lib media opt root sbin sys usr vmlinuz
It represents all directories as Linux file hierarchical system.
Fig. 1: Image showing Linux File Hierarchical System
Each directory contains various files according to specific use and configuration. Here I will shortly explain as to which type of file is contained under the various directories. User can see each directory and associated file from command prompt.
Root – Each directory and single file starts with root. Root has only write privileges to do anything with file.
Etc – It contains configuration file of application or program.
Bin – It contains binary executable file. Linux commands are located under bin directory like ps, cp, grep, chmod etc.
Sbin – It also contains system binary executable file but is located in system administrator command like ifconfig, reboot, fdisk etc.
Proc – It contains information of system process. It is virtual file system and contains all information of running process and shared resource with Process ID.
Tmp – It is a temporary directory which contains all temporary files created by system and user. All files under this directory are deleted when system is rebooted.
Usr – It contains User program and application like binary file, source code, documentation etc. The usr directory contains various sub directories for specific collection of file.
Home – It is a directory where user can store his/her personal data. User can also create new directory here.
Lib – It contains system library.
Mnt – It is temporary mount directory where system administrator can mount file systems.
Media – It is temporary mount directory for removable devices like cdrom andfloppy disk which are located under media directory.
Srv – It stores the related information of specific server services.
Boot – It contains file related to boot loader.
Filed Under: Tutorials
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.