Skip to content

File Types in Linux — Understanding Every Type of File

Everything in Linux is treated as a file. Regular files, directories, devices, sockets, pipes, symbolic links, and even hardware are represented as files. Understanding Linux file types is fundamental for Linux administrators, DevOps engineers, Cloud Architects, SREs, and Security professionals.


Learning Path

Linux Mastery → Module 4: File Management and Permissions → Lesson 1

Difficulty: Beginner

Reading Time: 35 Minutes

Course Progress

Course: Linux Mastery

Module: File Management and Permissions

Lesson: 1 of 10


What You'll Learn

After completing this lesson, you'll be able to:

  • Understand Linux file types
  • Identify different file types
  • Use ls -l to determine file types
  • Understand device files
  • Differentiate hard links and symbolic links
  • Recognize sockets and named pipes
  • Understand the "Everything is a File" philosophy

Prerequisites

Before starting this lesson, complete:

  • Module 1 – Linux Fundamentals
  • Module 2 – Command Line Essentials
  • Module 3 – Text Processing

Why Learn File Types?

Imagine you're troubleshooting a production server.

You see:

-rwxr-xr-x

drwxr-xr-x

lrwxrwxrwx

crw-rw----

srwxrwxrwx

Questions:

  • Which one is a directory?
  • Which one is a symbolic link?
  • Which one is a device?
  • Which one is a socket?

Understanding file types allows you to confidently manage Linux systems.


Linux Philosophy

One of the most famous Linux principles is:

Everything is a File

Examples include:

  • Text files
  • Directories
  • Hard disks
  • SSDs
  • USB devices
  • Printers
  • Network sockets
  • Pipes
  • Processes (through /proc)
  • System information (through /sys)

This unified design simplifies system administration and programming.


Viewing File Types

Use:

ls -l

Example output:

-rw-r--r-- 1 basha users 1200 Jan 10 notes.txt

drwxr-xr-x 2 basha users 4096 Jan 10 Documents

lrwxrwxrwx 1 basha users   12 Jan 10 latest -> release-v2

The first character indicates the file type.


Linux File Type Indicators

Symbol File Type
- Regular File
d Directory
l Symbolic Link
c Character Device
b Block Device
p Named Pipe (FIFO)
s Socket

1. Regular File (-)

Example:

-rw-r--r--

Regular files store:

  • Documents
  • Source code
  • Images
  • Videos
  • Shell scripts
  • Configuration files

Examples:

notes.txt

script.sh

photo.jpg

config.yaml

Create:

touch notes.txt

Verify:

ls -l notes.txt

2. Directory (d)

Example:

drwxr-xr-x

Directories organize files.

Create:

mkdir projects

View:

ls -ld projects

Examples:

/home

/etc

/var

/opt

/usr

3. Symbolic Link (l)

Example:

lrwxrwxrwx

A symbolic link (soft link) points to another file or directory.

Create:

ln -s notes.txt latest-notes

View:

ls -l latest-notes

Output:

latest-notes -> notes.txt

Common use cases:

  • Current application version
  • Shared configuration
  • Simplified paths

4. Character Device ©

Example:

crw-rw-rw-

Character devices transfer data one character at a time.

Examples:

/dev/tty

/dev/random

/dev/null

/dev/zero

View:

ls -l /dev/null

Output:

crw-rw-rw-

5. Block Device (b)

Example:

brw-rw----

Block devices transfer data in blocks.

Examples:

/dev/sda

/dev/sdb

/dev/nvme0n1

View:

ls -l /dev/sd*

Typical block devices include:

  • HDDs
  • SSDs
  • USB drives
  • Virtual disks

6. Named Pipe (FIFO) (p)

Example:

prw-r--r--

Named pipes enable communication between processes.

Create:

mkfifo mypipe

View:

ls -l mypipe

Example output:

prw-r--r--

Named pipes are commonly used in:

  • Shell scripts
  • Inter-process communication
  • Streaming data

7. Socket (s)

Example:

srwxrwxrwx

Sockets allow communication between processes.

Examples:

Docker

MySQL

PostgreSQL

Nginx

systemd

View socket files:

find /run -type s

Or:

find /var/run -type s

The file Command

Determine a file's actual type:

file notes.txt

Output:

ASCII text

Executable:

file /bin/ls

Output:

ELF 64-bit executable

Image:

file photo.jpg

Output:

JPEG image data

Unlike ls, the file command examines the file contents rather than relying on the filename.


Find Files by Type

Find directories.

find . -type d

Regular files.

find . -type f

Symbolic links.

find . -type l

Named pipes.

find . -type p

Sockets.

find . -type s

Block devices.

find /dev -type b

Character devices.

find /dev -type c

Real Production Examples

List all symbolic links.

find /etc -type l

Find all sockets.

find /run -type s

List block devices.

lsblk

Display device files.

ls -l /dev

Find executable shell scripts.

find . -type f -name "*.sh"

Production Perspective

Linux administrators frequently work with:

  • Configuration files
  • Device files
  • Symbolic links
  • Docker sockets
  • Kubernetes volume mounts
  • Named pipes
  • Storage devices

Understanding file types is essential for troubleshooting permissions, storage, and process communication.


Hands-on Lab

Task 1

Create a regular file.

touch file.txt

Task 2

Create a directory.

mkdir lab

Task 3

Create a symbolic link.

ln -s file.txt file-link

Task 4

Create a named pipe.

mkfifo mypipe

Task 5

List all files.

ls -l

Identify the file type using the first character.


Task 6

Inspect file types.

file file.txt

file /bin/bash

Task 7

Find all symbolic links.

find . -type l

Task 8

Display block devices.

lsblk

Command Deep Dive

Command Purpose Production Example
ls -l Display file type Daily administration
file Identify actual file type Troubleshooting
find -type f Find regular files Automation
find -type l Find symbolic links System audits
lsblk Display storage devices Storage management
mkfifo Create named pipes IPC

Production Troubleshooting Scenario

Scenario

A web application suddenly stops responding.

Investigation:

  1. Check if the Nginx socket exists.
  2. Verify the symbolic link to the latest release.
  3. Confirm mounted storage devices.
  4. Inspect configuration file types.

Commands:

find /run -type s

ls -l /var/www/current

lsblk

file /etc/nginx/nginx.conf

These checks quickly identify missing sockets, broken symbolic links, storage issues, or incorrect file types.


Best Practices

  • Always verify file types before modifying or deleting files.
  • Use symbolic links for application version management.
  • Use file when the extension is misleading or missing.
  • Avoid manually creating device files unless necessary.
  • Understand the difference between block and character devices.

Common Mistakes

❌ Assuming file extensions determine file type.

✅ Linux determines file types by metadata and content, not by filename extensions.


❌ Confusing symbolic links with hard links.

✅ A symbolic link points to a pathname, while a hard link references the same inode. (Hard links are covered in a later lesson.)


❌ Deleting a symbolic link's target instead of the link.

✅ Always verify with:

ls -l

before removing files.


Interview Questions

Beginner

  1. What does "Everything is a File" mean in Linux?
  2. Which symbol represents a directory?
  3. Which symbol represents a symbolic link?
  4. What command identifies the actual type of a file?

Intermediate

  1. Explain the difference between block and character devices.
  2. What is a named pipe?
  3. How are sockets used in Linux?
  4. Why is /dev/null a character device?

Architect Level

  1. Why does Linux represent devices as files?
  2. How do symbolic links simplify application deployments?
  3. How would you troubleshoot a broken service caused by a missing socket or symbolic link?

Summary

In this lesson, you learned:

  • Linux file types
  • File type indicators
  • Regular files
  • Directories
  • Symbolic links
  • Character devices
  • Block devices
  • Named pipes
  • Sockets
  • File inspection techniques

Understanding Linux file types is fundamental to managing filesystems, devices, and services. This knowledge forms the basis for permissions, storage management, and system administration.


Key Takeaways

  • Linux treats almost everything as a file.
  • The first character in ls -l indicates the file type.
  • Use file to inspect the actual content type.
  • Device files provide access to hardware.
  • Symbolic links simplify file and application management.
  • Named pipes and sockets enable communication between processes.

What's Next?

Hard Links in Linux — Understanding Inodes and File Linking

In the next lesson, you'll learn:

  • What hard links are
  • How Linux stores files using inodes
  • Creating and managing hard links
  • Differences between hard and symbolic links
  • Production use cases for hard links