Understanding UNIX / Linux file system

by nixcraft · 26 comments

A conceptual understanding of file system, especially data structure and related terms will help you become a successful system administrator. I have seen many new Linux system administrator w/o any clue about file system. The conceptual knowledge can be applied to restore file system in an emergency situation.

What is a File?

File are collection of data items stored on disk. Or it's device which can store the information, data, music (mp3), picture, movie, sound, book etc. In fact what ever you store in computer it must be inform of file. Files are always associated with devices like hard disk ,floppy disk etc. File is the last object in your file system tree. See Linux/UNIX - rules for naming file and directory names.

What is a directory?

Directory is group of files. Directory is divided into two types:

  • Root directory - Strictly speaking, there is only one root directory in your system, which is denoted by / (forward slash). It is root of your entire file system and can not be renamed or deleted.
  • Sub directory - Directory under root (/) directory is subdirectory which can be created, renamed by the user.

Directories are used to organize your data files, programs more efficiently.

Linux supports numerous file system types

  • Ext2: This is like UNIX file system. It has the concepts of blocks, inodes and directories.
  • Ext3: It is ext2 filesystem enhanced with journalling capabilities. Journalling allows fast file system recovery. Supports POSIX ACL (Access Control Lists).
  • Isofs (iso9660): Used by CDROM file system.
  • Sysfs: It is a ram-based filesystem initially based on ramfs. It is use to exporting kernel objects so that end user can use it easily.
  • Procfs: The proc file system acts as an interface to internal data structures in the kernel. It can be used to obtain information about the system and to change certain kernel parameters at runtime using sysctl command. For example you can find out cpuinfo with following command:

# cat /proc/cpuinfo

  • Or you can enable or disable routing/forwarding of IP packets between interfaces with following command:

# cat /proc/sys/net/ipv4/ip_forward
# echo "1" > /proc/sys/net/ipv4/ip_forward
# echo "0" > /proc/sys/net/ipv4/ip_forward

  • NFS: Network file system allows many users or systems to share the same files by using a client/server methodology. NFS allows sharing all of the above file system.
  • Linux also supports Microsoft NTFS, vfat, and many other file systems. See Linux kernel source tree Documentation/filesystem directory for list of all supported filesystem.

You can find out what type of file systems currently mounted with mount command:
$ mount
OR
$ cat /proc/mounts

What is a UNIX/Linux File system?

A UNIX file system is a collection of files and directories stored. Each file system is stored in a separate whole disk partition. The following are a few of the file system:

  • / - Special file system that incorporates the files under several directories including /dev, /sbin, /tmp etc
  • /usr - Stores application programs
  • /var - Stores log files, mails and other data
  • /tmp - Stores temporary files

See The importance of Linux partitions for more information.

But what is in a File system?

Again file system divided into two categories:

  • User data - stores actual data contained in files
  • Metadata - stores file system structural information such as superblock, inodes, directories

Next time I will write more about Metadata objects - superblock, inodes, directories with actual linux commands so that you can understand and master the concepts :)

Continue reading rest of the Understanding Linux file system series:

  • Part II - Understanding Linux superblock
  • Part III - An example of Surviving a Linux Filesystem Failures
  • Part IV - Understanding filesystem Inodes
  • Part V - Understanding filesystem directories
  • Part VI - Understanding UNIX/Linux symbolic (soft) and hard links
  • Part VII - Why isn't it possible to create hard links across file system boundaries?

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 26 comments… read them below or add one }

1 Ashish 01.18.06 at 12:38 pm

Hello Sir,

I would like to post my comments regarding file and directories definitation.

File:

It contains the metadata which includes inodes, date and stamp, rights and ownership filesize and type. It also has the link to the datablock which stores data on it.

Directories:

Directories are also files which contains filename to inode associations in its datablock so people says there are only files in Unix.

Thanks!
Ashish

2 nixcraft 01.18.06 at 8:14 pm

Nice ashish! I appreciate your post :)

3 Anonymous 01.30.06 at 11:37 pm

two typos

Procfs: The proc
___^____________
cat /proc/mounts
_______________^

4 Anonymous 01.30.06 at 11:40 pm

You didn’t mention Reiserfs which I think is a little short sighted. Many users prefer it to ext3, XFS, and JFS journaling filesystems. Once reiserfs v4 is merged we’ll see some cool features being made available to all other filesystems as well.

5 nixcraft 01.31.06 at 1:00 am

Anonymous, thanks. I really appreciate your help for spotting out typos and your post.

6 nixcraft 01.31.06 at 1:07 am

Yes, I just missed reiserfs v3 was quite stable v4 will take some to stable under 2.6 kernel.. I will update the post for reiserfs. Thanks for suggestion.

7 Anonymous 01.31.06 at 8:49 am

Quote “It contains the metadata which includes inodes, date and stamp, rights and ownership filesize and type. It also has the link to the datablock which stores data on it.”

I think this definition is wrong, a file by definition is a stream of data -the meta data is exactly that, its data about data.

The inode may be part of the operating systems fileing system, but it is NOT part of the file. For example if I copy a file from my linux system onto my windows system i lose the date/time/inode/mode/group – but I still have my “file”

Jon

8 Ashish 05.15.06 at 11:17 pm

Hey Jon,

This brings another querry in my mind.
Where file is storing the information about date, stamp, permissions, ownership and filesize?

BTW, I really do not have much information about windows file system. Is it same like Unix file system? Is it having inodes and other stuff?

Thanks!
Ashish Pathak

9 Thomas Scott 01.29.07 at 3:41 am

“A conceptual understanding of file system, especially data structure and related terms will help you become a successful system administrator”
———————-
But his job is easily taken away
by future s/w that manages all objects
files and folders , w/o a cmd line .
Automating objects , reduces the
kernel size , runs much faster .
————————

Pocket boxes are $5 cpu , & 64MB .
And Intel lost its grip ( 20 countries
make ARM !). No more WinTel .

Ppl will hack h/w and s/w into
a pocket box that will run fast
enuf to do everything .
OpSys that has NO cmd line , true G.U.I.
uses images ONLY , has no text keyboard.
But since OpSys is non-text , one
can create apps in hours ! Most of
the proceedures will be in kernel ,
all you need is to chain these proc’s
in the proper order to create your app .

Yes , i know Linux is your paycheck ,
sorry …..

10 Arnab 06.11.07 at 8:01 am

Hey friends can any one answer this following questioon plz.. it’s urgent.. I need ur help.

” Now a days memories are large and cheap.Therefore,when a file is opened it is simpler and faster to fetch a new copy of the i-node into the i-node table, rather than searching the entire table to see if it is already there” True or False?? – Justify

11 abhi 11.14.07 at 3:11 pm

@Thomas Scott,

Thomas, a question : How does your hypothetical keyboard-less OS stores your resume to begin with? or any data? Just curious.

And what if someone wants to create something new? How do these “most procedures” cope with that then? Sheesh!

If you don’t understand computers, or are plain simple drunk, why bother commenting at all? Why not just sleep off the effect of the wonderful liquor you have imbibed?

12 koulis 12.11.07 at 4:13 pm

hi,
i very appreciate this tutorial but
part-ii ( http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/11/understanding-unixlinux-filesystem.php ) forwords to a 404 error.
pls fix toc ontinue reading :D

13 koulis 12.11.07 at 4:28 pm

ok i googled a bit and found the correct url ( http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-superblock.html )

pls fix it for others and sorry for posting a comment instead of mail.

14 vivek 12.11.07 at 4:53 pm

koulis,

I’ve updated php regex and it should now redirect to correct url.

15 srees 12.13.07 at 2:50 pm

will linux support RAW file system?
my USB drive was changed by Trojan horse to Raw.
how can i recover it?

16 ami 01.02.08 at 8:21 am

Is there a way to add custom properties (attirbutes) to iNode structure?

17 savi 02.26.08 at 5:43 am

diagrms would have helped the user to understand the things easily.

18 AMITKUMAR 05.15.08 at 6:51 am

hi, all

i’ve to design ext3 linux file system, so please any body can suggest me, that from where i can get the proper knowledge of ‘ext3 linux file system’ architecture/ structure

19 franklin 08.04.08 at 5:52 am

Can Someone clear my doubt in ext3 file system
what is meaning of journalising in ext3 and describe?

20 franklin 08.04.08 at 6:06 am

nixcrft excellent and delicious site,thanks Vivek sir.

21 vivek 08.04.08 at 8:41 am

Franklin,

Under ext3 there is a journal where file system logs the changes before committing them to disk / main file system. ext3 less likely to become corrupted in the event of power failure or system crash. See this tutorial for more info.

22 nari 12.24.08 at 9:01 am

Q). Files (Types of files, attributes, device files, usage, how to control hw with files, cdrom, hdd, tapedrive)

23 veera 02.02.09 at 10:02 am

hi,
I wants to find dump(crash dump) file system name and FS type and how many blocks it has? for all unix plat forms linix ,aix,hp-ux and solaris.
please any body suggest the commands for getting above values.
Thanks,
Veera.

24 HungryCoder 02.16.09 at 7:09 pm

nice article. it helped me a lot. thank u so much.

25 amin 04.15.09 at 6:37 am

unix or linux are support FAT / NTFS

26 AMOL 08.05.09 at 7:15 pm

HI NIX CAN U NAME SITE TO DONL LINUX SUUGEST ME BEST VERSION
I AM USING
CORE 2 DUO
THANKS & REGARDS,
941.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: