DEV Community

Aryan Vaishnani
Aryan Vaishnani

Posted on

File Types (Regular, Directory, Link, Device, Socket, Pipe)

In Linux, everything is treated as a file.

Linux supports different file types for:

  1. Data storage
  2. Directories
  3. Hardware devices
  4. Communication
  5. Inter-process communication

Main Linux File Types

File Type Symbol Purpose
Regular File - Store data
Directory d Store files/folders
Symbolic Link l Point to another file
Character Device c Character-based devices
Block Device b Block storage devices
Socket s Process communication
Named Pipe (FIFO) p Data transfer between processes

Check File Types

Use:

ls -l

Example output:

  • rw-r--r-- file.txt

drwxr-xr-x  documents

lrwxrwxrwx  link -> file.txt

The first character shows the file type.

1. Regular File -

Purpose

Stores:

  1. Text
  2. Scripts
  3. Images
  4. Programs
  5. Logs

Examples

file.txt
script.sh
app.log
image.png

Example Output

  • rw-r--r-- file.txt
  • indicates regular file.

Real-World Usage

Log Files

/var/log/syslog

Shell Scripts

backup.sh

2. Directory d

Purpose

Stores:

  1. Files
  2. Other directories

Example

drwxr-xr-x projects

d indicates directory.

Common Directories

/home
/etc
/var

Real-World Usage

Kubernetes Manifests Folder

mkdir k8s

3. Symbolic Link l

Purpose

Points to another file or directory.

Similar to shortcuts in Windows.

Create Symbolic Link

ln -s original.txt link.txt

Example Output

lrwxrwxrwx link.txt -> original.txt

l indicates symbolic link.

Real-World Usage

Application Deployment

ln -s /opt/app/current current_app

Very common in DevOps deployments.

Benefits

  1. Easy version switching
  2. Shared configurations
  3. Flexible file management

4. Character Device File c

Purpose

Handles character-by-character device communication.

Examples

/dev/tty
/dev/random

Example Output

crw-rw-rw- /dev/tty

c indicates character device.

Real-World Usage

Keyboard Input

/dev/tty

Random Number Generator

/dev/random

5. Block Device File b

Purpose

Represents block storage devices.

Data transferred in blocks.

Examples

/dev/sda
/dev/nvme0n1

Example Output

brw-rw---- /dev/sda

b indicates block device.

Real-World Usage

Disk Management

lsblk

Shows block devices.

Used For

  1. Hard disks
  2. SSDs
  3. USB drives

6. Socket File s

Purpose

Used for communication between processes.

Examples

/var/run/docker.sock

Example Output

srw-rw---- docker.sock

s indicates socket.

Real-World Usage

Docker Communication

/var/run/docker.sock

Docker client communicates with Docker daemon through socket.

Common Services Using Sockets

  1. Docker
  2. MySQL
  3. Nginx
  4. systemd

7. Named Pipe (FIFO) p

Purpose

Used for inter-process communication.

FIFO = First In First Out

Create Named Pipe

mkfifo mypipe

Example Output

prw-r--r-- mypipe

p indicates pipe.

Real-World Usage

Process Communication

One process writes:

echo "Hello" > mypipe

Another reads:

cat mypipe

File Type Symbols Summary

Symbol File Type
- Regular file
d Directory
l Symbolic link
c Character device
b Block device
s Socket
p Named pipe

Useful Commands for File Types

Identify File Type

file filename

Example

file script.sh

Output:

Bourne-Again shell script

List Detailed File Types

ls -l

Find Specific File Types

Find Symbolic Links

find . -type l

Find Directories

find . -type d

Find Regular Files

find . -type f

Top comments (0)