In Linux, everything is treated as a file.
Linux supports different file types for:
- Data storage
- Directories
- Hardware devices
- Communication
- 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:
- Text
- Scripts
- Images
- Programs
- 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:
- Files
- 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
- Easy version switching
- Shared configurations
- 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
- Hard disks
- SSDs
- 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
- Docker
- MySQL
- Nginx
- 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)