Linux Training : h. File types

  • regular files and directories

    These are files like text and image files. Directories are containers for files and other directories. On the hard drive, each file requires at least one inode plus a block for the data in the file. A directory requires only a single inode unless the number of files or directories directly under exceeds the storage size of the one inode. Inodes store the metadata associated with a filesystem.
  • Symlinks are like short cuts but performed at the filesystem level. There are two types, hard and soft. A hard link is a filesystem pointer to the original file, inode and all. There is no new inode created for a hard link. Instead there are two filenames listed in that inode. A soft link does have a new inode that points to the inode of the original file. If the original file in a soft link is deleted, the link is broken. If the link is deleted the original file is still available.
    If the original file of a hard link is deleted the linked file still has the data. Only the filename of the original file is the removed from the inode.
    A file's inode can be viewed with ls -i <filename>.

    Directories can't be hardlinked and hardlinks can't cross filesystems. The inode number is unique only within a filesystem boundary.

  • special files

    There are two special file types that are also used in Linux systems: sockets and named pipes. They are similar in that they both act as a conduit for data to flow through. However a socket is explicitly a networking device while a named pipe is only for use by the local system itself. A socket has as "s" as it's designator seen in ls -la while a named pipe has a "p". A good article on pipes and using them is in Linux Journal. Additionally a good introductory article series for network programming, and thus sockets, is also in Linux Journal.
File types exercise

Write a script to determine the inode number of every socket and named pipe in /tmp. Include the owner in the report