Now just see inode of both file1 and file2:$ ls -i file1 782263$ ls -i file2 782263

As you can see inode number is same for hard link file called file2 in inode table under /home file system. Now if you try to create a hard link for /tmp file system it will lead to confusing references for UNIX or Linux file system. Is that a link no. 782263 in the /home or /tmp file system? To avoid this problem UNIX or Linux does not allow creating hard links across file system boundaries. Continue reading rest of the Understanding Linux file system series (this is part VII):

An inode identifies the file and its attributes such as file size, owner, and so on. A unique inode number within the file system identifies each inode. But, why to delete file by an inode number? Sure, you can use rm command to delete file. Sometime accidentally you creates filename with control characters or characters which are unable to be input on a keyboard or special character such as ?, * ^ etc. Removing such special character filenames can be problem. Use following method to delete a file with strange characters in its name:

Please note that the procedure outlined below works with Solaris, FreeBSD, Linux, or any other Unixish oses out there:

Find out file inode

First find out file inode number with any one of the following command:

Note you can also use add \ character before special character in filename to remove it directly so the command would be:$ rm "\+Xy \+\8"

If you have file like name like name “2005/12/31” then no UNIX or Linux command can delete this file by name. Only method to delete such file is delete file by an inode number. Linux or UNIX never allows creating filename like 2005/12/31 but if you are using NFS from MAC OS or Windows then it is possible to create a such file.

We use DNS (domain name system) to translate between domain names and IP addresses. For example, one can use the dig command/host command for DNS lookup on a Linux and Unix-like systems. Similarly, Linux files are referred by file names, not by inode number. So what is the purpose of a directory? You can group the files according to your usage. For example, all configuration files are stored under /etc/ directory. So the purpose of a directory is to make a connection between file names and their associated inode number. Inside every directory, you will find out two sub-directories named:

. (single period) – The current directory

.. (double period) – The pointer to previous directory i.e. the directory immediately above the one I am in now. The ‘..‘ appears in every directory except for the root directory. The ‘..‘ always points to the same inode as ‘.‘

Use the ls command to list files and directories including . and .. directories on Linux or Unix:ls -laFind the . and .. directories on Linux or Unix-like systems using the ls command

Directory

A directory contained inside another directory is called a sub-directory. At the end the directories form a tree structure. Use the tree command to see directory tree structure:$ tree /etc | lessUse tree command to list contents of directories in a structure like format Again a directory has an inode just like a file. It is a specially formatted file containing records which associate each name with an inode number. Please note the following limitation of directories under ext2/3 file system:

There is an upper limit of 32768 subdirectories in a single directory

There is a “soft” upper limit of about 10-15k files in a single directory

Ext4 and other modern Linux file systems allows an unlimited number of subdirectories

However according to official documentation of ext2/3 file system points that using a hashed directory index (which is under development) allows 100k-1M+ files in a single directory without performance problems. Here are my two favorite bash shell alias commands related to directory :alias ..='cd ..' alias d='ls -l | grep -E "^d"'

Unix and Linux directory management commands

A list of standard Linux/Unix commands to work with directories and files:

This is second part of “Understanding UNIX/Linux file system”, part I is here. Let us take an example of 20 GB hard disk. The entire disk space subdivided into multiple file system blocks. And blocks used for what?

Unix / Linux filesystem blocks

The blocks used for two different purpose:

Most blocks stores user data aka files (user data).

Some blocks in every file system store the file system’s metadata. So what the hell is a metadata?

In simple words Metadata describes the structure of the file system. Most common metadata structure are superblock, inode and directories. Following paragraphs describes each of them.

Superblock

Each file system is different and they have type like ext2, ext3 etc. Further each file system has size like 5 GB, 10 GB and status such as mount status. In short each file system has a superblock, which contains information about file system such as:

File system type

Size

Status

Information about other metadata structures

If this information lost, you are in trouble (data loss) so Linux maintains multiple redundant copies of the superblock in every file system. This is very important in many emergency situation, for example you can use backup copies to restore damaged primary super block. Following command displays primary and backup superblock location on /dev/sda3:# dumpe2fs /dev/hda3 | grep -i superblock Output:

Primary superblock at 0, Group descriptors at 1-1
Backup superblock at 32768, Group descriptors at 32769-32769
Backup superblock at 98304, Group descriptors at 98305-98305
Backup superblock at 163840, Group descriptors at 163841-163841
Backup superblock at 229376, Group descriptors at 229377-229377
Backup superblock at 294912, Group descriptors at 294913-294913

Continue reading rest of the Understanding Linux file system series (this is part II):