Linux File System
If you are in IT Field or thinking of getting into it. Then a deep understanding of Linux is very important. In this article, we are going to get a decent understanding of Linux File System.
What is a File System ?
OS stores data on disk drives using a structure called a file system, consisting of files, directories and the information needed to access and locate them. There are many different types of file systems. In general, improvements have been made to file systems with new releases of operating systems and each new filesystem has been given a different name.
E.g. EXT3;EXT4;XFS;NTFS;FAT etc
Unlike windows, Linux filesystems store information in a hierarchy of directories and files.
File Structure
All the files and folders in Linux is structured in an hierarchy order. the uses of each file folder is listed as follows
- /boot Contains file that is used by the bootloader (grub.cfg)
- /root Root user’s home directory
- /dev System devices (e.g. disk, cdrom, speakers, flash drive, keyboard etc.)
- /etc Configuration Files
- /bin -> /usr/bin Everyday User Commands
- /sbin -> /usr/sbin System/Filesystem Commands
- /opt Optional add-on applications (Not part of OS apps)
- /proc Running Processes (Only exit in Memory)
- /lib -> /usr/lib C programming library files needed by commands and apps
- /tmp Directory for temporary files needed by commands and apps
- /home Directory of User
- /var System Logs
- /run System daemons that start very early to store PID files
- /mnt To mount external filesystems
- /media For cdrom Mounts
File Types in Linux
- – Regular File
- d Directory
- l Link
- c Device File
- s Socket File
- p Named File
- b Blockfile
File Paths
There are two paths to navigate to a filesystem :
- Absolute Path
- Relative Path
An absolute path always begins with a “/”.This indicates that the path starts at the root directory. An example of an absolute path is :
cd /var/log/httpd
A relative path does not begin with a “/”.It identifies a location relative to your current position. An example of a relative path is :
cd /var
cd log
cd httpd
Navigation Through Terminal
These are some important command for navigating in an UNIX filesystem:
- cd
- pwd
- ls
“cd” stands for change directory. It is the primary command for moving you around the file system. “pwd” stands for print working directory. It tells you where you are in the system. “ls” stands for list. It lists all the contents in a directory.
Now, here some attributes can be used with ls to increase its capabilities.
ls -al
ls -a
When we are using -al along with ls we can see the items are listed in a detailed manner,to understand every aspect of the result, have a look to the file types section of the article. The result explains :
TYPE | No. of Links | Owner | Group | Size | Month | Day | Time | Name |
drwxr-xr-x | 21 | root | root | 4096 | May | 27 | 10:20 | var |
drwxr-xr-x | 1 | root | root | 15 | May | 27 | 10:22 | bin |
-rw-r-r– | 1 | root | root | 0 | Jun | 2 | 11:15 | testfile |
File System Color Codes
- Blue = Directory
- White = File
- Green = Executable
- Sky Blue = Symbolic Link
- Pink = Graphic Image File
- Red = Archive file (tar)
- Red with black background = Broken Link
Coping Files and Folders
Coping and moving files and folders from one directory to another can be done with these commands:
- Copying Specific Files
- cp oldfilepath newfilepath
- Moving Files
- mv oldfilepath newfilepath
- Copying Directories
- cp -r olddirpath newdirpath
- Moving Directories
- mv -r olddirpath newdirpath
Creating Files and Directories
A file can be created in linux with the help of touch command or through a text editor like nano. For creating a blank file using touch, this command can be used:
touch testfile
And for creating a directory, “mkdir” command is used:
mkdir testfile
Reading and Removing Files and Directories
A file can be read with the cat command for example:
cat testfile.txt
And for removing a file “rm can be used”. For removing a directory -r attribute must be specified:
rm testfile rm -r testdir
That’s all for now. If you want to know something more, don’t forget to check out our YouTube channel for a better understanding. For any doubt you can reach us through the comments or through the contact us page.