Linux下一切皆文件，设备也被映射为文件；（依据在哪？）

• inode的简介；
• 整理一个典型的文件系统ext2 （参考鸟哥私房菜）
• 作用？
• 组成？（基本原理）
• 磁盘扩容等；

文件系统基本知识

• 一切皆文件，文件夹本质也是文件、打印机等外部设备也是文件；
• 每个文件占用一个inode，inode指向文件的真正内容；
• 读取文件内容，需要先通过文件名指向正确的inode编号，然后获取文件内容；
• 文件夹的内容是其下属所有文件的名称与inode的对应关系；

When to use Hard Link:

• Storage Space: Hard links takes very negligible amount of space, as there are no new inodes created while creating hard links. In soft links we create a file which consumes space (usually 4KB, depending upon the filesystem)
• Performance: Performance will be slightly better while accessing a hard link, as you are directly accessing the disk pointer instead of going through another file.
• Moving file location: If you move the source file to some other location on the same filesystem, the hard link will still work, but soft link will fail.
• Redundancy: If you want to make sure safety of your data, you should be using hard link, as in hard link, the data is safe, until all the links to the files are deleted, instead of that in soft link, you will lose the data if the master instance of the file is deleted.

When to use Soft Link:

• Link across filesystems: If you want to link files across the filesystems, you can only use symlinks/soft links.
• Links to directory: If you want to link directories, then you must be using Soft links, as you can’t create a hard link to a directory.

• 为什么？最上面的symbolic link图示对吗？创建symbolic link时，a new file is created with a new inode；但是新的直接指向源文件的inode？还是新的inode指向新文件？具体如何匹配的？

查看Inode信息

指定文件的Inode信息

[ningg@localhost ~]$stat . File: '.' Size: 4096 Blocks: 8 IO Block: 4096 directory Device: 805h/2053d Inode: 10330113 Links: 15 Access: (0700/drwx------) Uid: ( 500/ storm) Gid: ( 500/ storm) Access: 2015-01-28 16:58:00.000000000 +0800 Modify: 2015-01-28 16:46:52.000000000 +0800 Change: 2015-01-28 16:46:52.000000000 +0800 [ningg@localhost ~]$ ls -dil .
10330113 drwx------. 15 storm storm 4096 Jan 28 16:46 .


• 计算一个文件夹对应的Links数：针对一个文件夹的所有hard link个数，新建一个文件夹时，初始Links=2，因为在文件夹内部存在文件.，其也为指向当前目录的hard link；当在文件夹下创建子文件夹时，由于子文件夹下的..文件存在，文件夹的Links数也会增加；

文件系统的Inode信息

[ningg@localhost ~]\$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1            1875968  293264 1582704   16% /
none                  210613     764  209849    1% /dev
none                  213415       9  213406    1% /dev/shm
none                  213415      63  213352    1% /var/run
none                  213415       1  213414    1% /var/lock
/dev/sda2            7643136  156663 7486473    3% /home


# 默认为 TARGET 文件创建一个hard link文件，并命名为LINK_NAME

ln -s [TARGET] [LINK_NAME]


Top