Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Types of Files

Lesson 10 of 32 in the free Design of Unix Operating System notes on Siksha Sarovar, written by Rohit Jangra.

Introduction

In UNIX, the philosophy is "everything is a file". This means that not only regular data files, but also directories, devices, and communication channels are all treated as files. The kernel distinguishes between different file types using the inode.

Types of Files in UNIX

1. Regular Files (-):

  • The most common type of file.
  • Contains data — text, binary, programs, images, etc.
  • Can be created by editors, compilers, or redirecting output.
  • Example: -rw-r--r-- 1 user group 1024 Feb 17 file.txt

2. Directory Files (d):

  • A special file that contains a list of (filename, inode number) pairs.
  • Acts as a container for other files and subdirectories.
  • Every directory has at least two entries: . (self) and .. (parent).
  • Example: drwxr-xr-x 5 user group 4096 Feb 17 mydir

3. Character Special Files (c):

  • Represent devices that transfer data one character at a time.
  • Found in the /dev directory.
  • Examples: Terminal (/dev/tty), Keyboard, Mouse.
  • Example: crw-rw-rw- 1 root tty 5, 0 Feb 17 /dev/tty

4. Block Special Files (b):

  • Represent devices that transfer data in blocks (chunks of bytes).
  • Also found in /dev.
  • Examples: Hard disk (/dev/sda), USB drive.
  • Example: brw-rw---- 1 root disk 8, 0 Feb 17 /dev/sda

5. Named Pipes (FIFO) (p):

  • A special file used for Inter-Process Communication (IPC).
  • Data written by one process can be read by another, following First-In, First-Out order.
  • Created using the mkfifo command.
  • Example: prw-r--r-- 1 user group 0 Feb 17 mypipe

6. Symbolic Links (Soft Links) (l):

  • A file that points to another file by its pathname.
  • Like a shortcut — if the original file is deleted, the link becomes broken (dangling link).
  • Created using ln -s.
  • Example: lrwxrwxrwx 1 user group 11 Feb 17 link -> target.txt

7. Socket Files (s):

  • Used for network communication between processes (IPC over a network or locally).
  • Common in client-server architectures.
  • Example: srwxrwxrwx 1 root root 0 Feb 17 /var/run/mysqld.sock

Comparison Table

TypeSymbolExamplePurpose
Regular File-file.txtStores data
Directorydmydir/Contains other files
Character Devicec/dev/ttyChar-by-char I/O
Block Deviceb/dev/sdaBlock-based I/O
Named PipepmypipeIPC (FIFO)
Symbolic LinklshortcutPoints to another file
Socketsmysql.sockNetwork/local IPC

Hard Links vs Symbolic Links

FeatureHard LinkSymbolic (Soft) Link
Commandln file1 file2ln -s file1 file2
Points toSame inodeFile path (name)
Cross File SystemsNoYes
If original deletedData still accessibleLink becomes broken/dangling
Inode numberSame as originalDifferent from original
Can link directoriesNo (usually)Yes

Summary

  • UNIX has 7 types of files: Regular, Directory, Character Device, Block Device, Named Pipe, Symbolic Link, and Socket.
  • Each type is identified by the first character in the ls -l output.
  • Hard links share the same inode; symbolic links point to a pathname.