Linux: Filesystem

All the data in linux is organized into files. All files are then organized into directories, and these directories are further organized into a tree structure which is called as filesystem.

A linux operating system have following directory structure.

Let's understand each directory and purpose of the directory in linux operating system:

Directory Description
/ It is called root directory. Every single directory starts from root file system.Only root user has write permission to this directory.
/bin /bin directory contains user binariy executables like ls, ping, grep commands etc...Command linux commands that you use are located in this directory.
/sbin /sbin contains system binrary executable.This directory contains commands that are used by system administrator for maintenance purpose. i.e. ipconfig, iptables etc...
/etc /etc directory contains configuration files for different programs. For example if you have installed php in your operating system configurations for your php will be stored here.
/dev this directory contains terminal device files i.e. usb device etc...
/proc this directory contains file regarding processes running on your operating system
/var this directory contains variable files. i.e. system logs, mysql logs or any other logs can be found here.
/tmp this directory contains temporary files. Files in this directory can be deleted when system is rebooted.
/usr this directory contains library, binary or documentation files. In this directory we have /bin and /sbin directories for user programs,
/home this directory is used to store user personal data. For each user it will create a new directory inside /home directory
/boot this directory contains files that are necessary when system is booted
/lib this directory contains system libraries that are installed in /bin and /sbin. /bin and /sbin contains executable files that depends on library files which can be stored in  /lib directory.
/opt this directory contains some optional files required by third party software or applications
/mnt this directory called mount directory. You can mount CD or USB device etc... data here.
/media this directory contains files used by removable media devices like CD, Floppy or USB etc..
/srv this directory contains service data

Different types of file types

In linux two mostly used file types are files and directories. However there are more file types when you actually work with linux. Some of the file types are listed below:

symbol meaning
- regular file i.e. text files, images, binary files, shared libraries etc..
d directory
c charcter device file
b block device file
s local socker file
p named pipe
l symbolic link

How to check file type in linux?

Now, that you know 7 types of file types in linux you are curious to know how you can identify these types. You can use ls command to check file type.

For example: let's create a directory and check the file type:

# create a new directory
mkdir test

# check the file type of this directory
ls -ld test/

# sample output from above command
drwxr-xr-x  3 sandip programmer  96  5 Aug 11:39 test/

Let's understand above output what does each word mean in above output:

Charater/Word Meaning
First letter First letter in above output show the file type
Next nine letters Next nine letters show the file permissions for user, group and others i.e. r-read, w-write, x-execute
Link count the number of different directory entries that all point to the inode associated with the object.
owner shows creator of the file type
group shows group for owner
file size total size of current file type
last modified date shows last modifled date for given file type
name shows name given to current file type

Useful commands for file management

The followings are some of the commands commonly used when working with files and directories in linux:

Command Desccription
pwd prints the current working directory i.e. shows you which directory you are on right now
cd change directory or navigate to different directory
ls shows you all files and directories for given location
touch to create a new blank file
mkdir to create a new directory
less to view huge files without opening huge file at once
cp copy files from one to other location
move move file from one to other location or rename a file
file check the type of the file
more unsed to control the display of output of a file, lets you page through the results
cat to show content of the given file
rm remove a file
rmdir remove a directory
wc it is used to count the characters, words, and lines in text files
dd command is used to convert and copy a file
ln command is used to make soft or hard link between files
tail prints the last 10 lines of the file
head prints the first 10 lines of the file