What are the 7 types of files in Linux and how do you identify them?
Linux recognizes 7 types of files: Regular files (-), Directory files (d), Character device files (c), Block device files (b), Named pipes / FIFOs (p), Socket files (s), and Symbolic links / Symlinks (l). Run ls -la in any directory — that very first character instantly identifies the file type. This guide covers all 7 in detail with real command examples, a full comparison table, and a sysadmin decision guide.
File Types
ls flag to reveal all
of files are Regular
Everything is a File
Foundation
Why Knowing Linux File Types Changes Everything
Understanding the 7 types of files in Linux is essential for every sysadmin. Your hard drive, your keyboard, your network socket, your running processes — Linux represents virtually everything through the unified abstraction of a file. Understanding the 7 types of files in Linux isn't optional theory for sysadmins — it's the foundation of how you read logs, debug devices, write shell scripts, and manage system resources.
Whether you're a complete beginner who just ran ls -l for the first time, or a seasoned Linux system administrator who wants to build on the Linux fundamentals, this guide covers all types of files in Linux with real command examples, a full comparison table, and a decision guide.
The single letter at the very start of ls -la output is your file type identifier. - means regular file, d means directory, l means symlink, and so on. Master the full ls command in Linux with examples — this tiny character carries enormous diagnostic value.
Commands
How to Identify File Types in Linux
Before diving into each of the 7 file types, here are the commands you'll actually use in practice:
ls -la— Lists all files with the type character as the first column. The most common method.file <filename>— Reads file headers and reports the type in human-readable form.stat <filename>— Shows detailed inode information including file type. See the official stat man page.find / -type [b|c|d|f|l|p|s]— Searches the filesystem for files of a specific type.
bash — identify file types
# List all file types in /dev ls -la /dev/ crw-rw-rw- 1 root tty 5,0 tty # c = character device brw-rw---- 1 root disk 8,0 sda # b = block device lrwxrwxrwx 1 root root 4 fd -> /proc/self/fd # l = symlink prw-r--r-- 1 root root 0 initctl # p = named pipe srw-rw-rw- 1 root root 0 log # s = socket # Plain-English description file /etc/passwd /etc/passwd: ASCII text # Find all symbolic links under /usr find /usr -type l -ls
Now let's go through each of the 7 types of files in Linux in detail.
Regular Files
TYPE 01
Regular Files — The Most Common File Type
Regular files are the most familiar type and make up the vast majority of everything you interact with daily. A regular file is any file that contains data — whether that data is plain text, compiled binary code, compressed archives, images, audio, or configuration. There is no special structure imposed by the operating system; it's just a stream of bytes stored on disk.
When you see a - as the first character in ls -la (e.g., -rw-r--r--), that's a regular file. These include your shell scripts, config files under /etc, log files, executables under /usr/bin, and all documents in your home directory. See also: Linux file management commands.
What counts as a Regular File?
According to the GNU Coreutils documentation, regular files include any file that is not a special file type — text, binary, scripts, archives, and more.
- Text files:
/etc/fstab,/etc/passwd,README.md— usecatto read them - Executable binaries:
/usr/bin/ls,/bin/bash - Shell and Python scripts:
deploy.sh,backup.py— view the shell scripting interview questions - Archives and compressed files:
tarball.tar.gz,package.rpm— use the compression & archiving cheat sheet - Image, audio, and video media files
- Compiled object files and shared libraries:
libc.so.6
bash — working with regular files
# Create a regular file touch myfile.txt echo "Hello Linux" > myfile.txt # Verify it's a regular file (note the leading dash -) ls -la myfile.txt -rw-r--r-- 1 user user 12 Jun 01 10:00 myfile.txt # Count all regular files in /etc find /etc -type f | wc -l
For executable scripts, always set appropriate permissions with chmod 755 script.sh and use a shebang line (e.g., #!/bin/bash) at the top so the kernel knows which interpreter to use. Brush up on basic Linux commands if you're just getting started.
Directory Files
TYPE 02
Directory Files — The Filesystem's Skeleton
Directory files map filenames to their corresponding inodes. Think of a directory as a table: one column holds the filename, the other holds the inode number pointing to the actual data on disk. In ls -la, they start with d (e.g., drwxr-xr-x).
Every Linux filesystem has at least one directory: / (the root). Everything else hangs from it, forming the hierarchical Linux directory structure. The cd command is what you use to navigate between them.
- Directories can contain both files and other directories (subdirectories)
- Every directory contains two hidden entries:
.(itself) and..(parent) - The link count in
ls -lashows how many subdirectories a directory contains - You cannot
cpa directory without the-r(recursive) flag — see the file management commands guide
bash — directory file operations
# Create a directory mkdir -p /opt/myapp/logs # Confirm it is a directory file (note leading 'd') ls -la /opt/ drwxr-xr-x 3 root root 4096 Jun 01 10:05 myapp # Find all directories under /var find /var -type d -maxdepth 2
Character Device Files
TYPE 03
Character Device Files — Sequential Data Streams
Character device files provide an interface to hardware devices that transfer data one byte at a time, with no buffering. Every keystroke from your keyboard passes through a character device. The Linux kernel exposes these as files in /dev. The Linux kernel device list documents every major and minor number officially.
Character devices appear in ls -la with a leading c. After permissions you'll see two numbers: the major number (driver) and minor number (device instance). Check the Linux system information commands to inspect them.
Common Character Device Files
/dev/tty— Current terminal (console)/dev/ttyS0— First serial port/dev/null— Null device; discards everything written to it/dev/zero— Produces an infinite stream of zero bytes/dev/randomand/dev/urandom— Cryptographic random number generators/dev/input/event0— Keyboard or mouse input events
bash — character device examples
# List character devices in /dev ls -la /dev/ | grep "^c" crw-rw-rw- 1 root tty 5, 0 Jun 01 tty crw-rw-rw- 1 root root 1, 3 Jun 01 null crw-rw-rw- 1 root root 1, 5 Jun 01 zero # Discard all output with /dev/null command_verbose > /dev/null 2>&1 # Generate a random password tr -dc A-Za-z0-9 < /dev/urandom | head -c 20
Use /dev/null as a data sink in cron jobs to suppress noisy output. Use /dev/urandom for fast, secure random data — equivalent to /dev/random since kernel 5.6.
Block Device Files
TYPE 04
Block Device Files — Storage Hardware Interface
Block device files provide an interface to storage hardware — hard drives, SSDs, USB drives, and RAID arrays. Unlike character devices, block devices read and write in fixed-size chunks (blocks), and the kernel caches them for fast random access.
Block devices live in /dev and begin with b. If you've ever run fdisk, parted, or LVM commands, you were working with block device files. The Linux kernel block layer documentation explains how block I/O is handled internally. Use df and du to monitor storage usage on block devices.
/dev/sda— First SATA/SCSI hard drive/dev/sda1— First partition on the first drive/dev/nvme0n1— First NVMe SSD/dev/vda— Virtual disk in KVM/QEMU virtual machines/dev/sr0— First CD/DVD drive/dev/loop0— Loop device (used to mount ISO images)
bash — block device operations
# List block devices lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 99G 0 part / # Show block device files in /dev ls -la /dev/ | grep "^b" brw-rw---- 1 root disk 8, 0 Jun 01 sda # Mount a block device mount /dev/sda1 /mnt/data
Writing directly to a block device (e.g., dd if=/dev/zero of=/dev/sda) will permanently destroy all data. Always verify device names with lsblk before any destructive operation. Consider a solid Linux server backup solution before any disk operations.
Named Pipes (FIFOs)
TYPE 05
Named Pipes (FIFOs) — Inter-Process Communication
Named pipes (FIFOs — First In, First Out) enable two separate, unrelated processes to communicate via a persistent file on disk. Unlike the anonymous pipe (|) in shell scripting, named pipes survive after a process exits. You can also explore Linux I/O redirection to understand how pipes fit into the bigger picture.
- Created with the
mkfifocommand (POSIX standard) ormknod name p - Reads block until a writer opens the pipe (and vice versa)
- Data flows in one direction only — use two FIFOs for bidirectional communication
- Used by system services like
syslogd,init, and print spoolers - No data is stored on disk — only the file entry (metadata) itself
bash — named pipe (FIFO) example
# Create a named pipe mkfifo /tmp/mypipe # Verify: note the 'p' at the start ls -la /tmp/mypipe prw-r--r-- 1 user user 0 Jun 01 10:20 /tmp/mypipe # Terminal 1: Write to the pipe echo "Hello from process 1" > /tmp/mypipe # Terminal 2: Read from the pipe cat /tmp/mypipe Hello from process 1
Socket Files
TYPE 06
Socket Files — Two-Way Process Communication
Socket files enable full-duplex, two-way communication between processes — on the same machine or across a network. Web servers, databases, Docker, and SSH all rely on sockets. Unlike named pipes, both sides can send and receive simultaneously.
Unix domain socket files live in /var/run/ or /tmp/ and start with s in ls -la. If you've used MySQL, you've connected through /var/run/mysqld/mysqld.sock. Socket files are also how the networking protocols on Linux communicate internally. See the Unix domain sockets man page for the full technical specification.
/var/run/docker.sock— Docker daemon socket/var/run/mysqld/mysqld.sock— MySQL server socket/run/systemd/private/journal.socket— systemd journal socket/tmp/.X11-unix/X0— X Window System display socket
bash — socket file identification
# Find all socket files on the system find / -type s 2>/dev/null # Check MySQL socket ls -la /var/run/mysqld/ srwxrwxrwx 1 mysql mysql 0 Jun 01 mysqld.sock # Check the Docker socket ls -la /var/run/docker.sock srw-rw---- 1 root docker 0 Jun 01 /var/run/docker.sock
The Docker socket (/var/run/docker.sock) grants full root-equivalent access to the Docker daemon. Never expose it to untrusted containers or users. Review the Linux server hardening checklist and top Linux security tools to protect your system.
Symbolic Links (Symlinks)
TYPE 07
Symbolic Links (Symlinks) — Flexible Filesystem Shortcuts
Symbolic links (symlinks or soft links) are pointer files that redirect access to another file or directory. When you read, write, or execute a symlink, the kernel transparently redirects the operation to the target.
Symlinks differ from hard links: they can cross filesystem boundaries and point to directories. They appear with l in ls -la. Learn more about hard links vs symbolic links in Linux in our file management commands guide.
Real-World Symlink Use Cases
- Version management:
/usr/bin/python3 → python3.11— switch versions by relinking - Nginx config: point
/etc/nginx/sites-enabled/apptosites-available/app - Shared libraries:
libssl.so → libssl.so.3.0.7 - Mounting and path simplification in multi-disk deployments
- Docker volume mounts — see the Docker management command cheat sheet
bash — symlink creation and management
# Create a symbolic link ln -s /usr/local/python3.11/bin/python3 /usr/bin/python3 # Verify it's a symlink (note 'l' and the '->' arrow) ls -la /usr/bin/python3 lrwxrwxrwx 1 root root 34 Jun 01 /usr/bin/python3 -> /usr/local/python3.11/bin/python3 # Nginx sites-enabled pattern ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp # Find broken symlinks find /usr -xtype l # Remove a symlink (use rm, NOT rmdir) rm /usr/bin/python3
Always use absolute paths when creating symlinks if they'll be accessed from different working directories. Use readlink -f <link> to resolve the full canonical path. See the ln command man page for all options. The find command with -xtype l is the fastest way to locate broken symlinks system-wide.
Reference
All 7 Linux File Types — Complete Comparison Table
The following table summarizes all types of files in Linux with their identifiers, locations, use cases, and creation commands:
Linux File Types Quick Reference
| File Type | ID | Location | Create With | Primary Use Case |
|---|---|---|---|---|
| Regular File | - |
Everywhere | touch, echo, cp | Data storage: text, binaries, scripts, archives |
| Directory | d |
Everywhere | mkdir | Filesystem hierarchy, organizing files |
| Character Device | c |
/dev/ | mknod (kernel) | Serial/streaming hardware: keyboard, terminal |
| Block Device | b |
/dev/ | mknod (kernel) | Storage hardware: HDDs, SSDs, USB, NVMe |
| Named Pipe (FIFO) | p |
/tmp/, /var/ | mkfifo | IPC between unrelated processes (one-way) |
| Socket File | s |
/var/run/, /tmp/ | socket() syscall | IPC full-duplex: databases, Docker, web servers |
| Symbolic Link | l |
Everywhere | ln -s | Aliases, version management, path shortcuts |
Decision Guide
Decision Table — Which Linux File Type Do You Need?
Use this decision table to quickly determine which of the 7 types of files in Linux applies to your situation:
Linux File Type Decision Table
| Your Situation / Goal | Use This File Type | Command / Tool | Notes |
|---|---|---|---|
| Store config, text, scripts, or binary data on disk | Regular File (-) |
touch / nano / vim | The default for almost everything |
| Group related files together | Directory (d) |
mkdir -p | Use -p for nested directories |
| Interface with keyboard, serial port, terminal | Character Device (c) |
Kernel creates; use /dev/tty* | Sequential, unbuffered I/O |
| Work with hard drives, SSDs, partitions, USBs | Block Device (b) |
lsblk / fdisk / mount | Buffered, random-access I/O |
| Pass data between two processes (one-way, persistent) | Named Pipe / FIFO (p) |
mkfifo /tmp/mypipe | Lightweight, no networking needed |
| Enable full two-way communication between processes | Socket File (s) |
Created by daemon processes | Use for databases, web servers, Docker |
| Create an alias or shortcut to another file/directory | Symbolic Link (l) |
ln -s /target /link | Can cross filesystems; use absolute paths |
| Manage multiple software versions (Python, Node.js) | Symbolic Link (l) |
ln -sf /new-version /usr/bin/app | Use -f to force-replace existing link |
| Silence noisy command output | Character Device (c) |
command > /dev/null 2>&1 | /dev/null discards all data |
| Generate secure random tokens or passwords | Character Device (c) |
cat /dev/urandom | tr ... | Prefer /dev/urandom on modern kernels |
Key Commands for Linux File Type Management
| Command | Purpose | Example Syntax | Works On |
|---|---|---|---|
| ls -la | Show file type identifier character | ls -la /dev/ | All types |
| file | Detect file type from content/headers | file /etc/passwd | Regular, device files |
| stat | Detailed inode and type information | stat /var/run/docker.sock | All types |
| find -type | Search by file type (f,d,l,b,c,p,s) | find / -type s 2>/dev/null | All types |
| mkfifo | Create a named pipe (FIFO) | mkfifo /tmp/pipe1 | Named Pipes |
| ln -s | Create a symbolic link | ln -s /src /dest | Symlinks |
| readlink -f | Resolve symlink to canonical path | readlink -f /usr/bin/python3 | Symlinks |
| lsblk | List block device tree | lsblk -o NAME,SIZE,TYPE | Block Devices |
Conclusion
Mastering Linux File Types Makes You a Better Engineer
Understanding all 7 types of files in Linux gives you a mental model that makes the entire operating system more predictable. When you see a socket file and know it means a service is running, when you trace a broken symlink to diagnose a version conflict, when you pipe data through a FIFO in a shell script — these are not isolated tricks. They're the result of truly understanding how Linux treats everything as a file.
To continue building on this foundation, explore: basic Linux commands, Linux process management, Linux security commands, Linux system monitoring, and Linux network administration. For authoritative external references: Linux Documentation Project, Linux kernel filesystem docs, and the Filesystem Hierarchy Standard (FHS 3.0) by the Linux Foundation.
Start Here
Master These
Deep Expertise
The single most practical habit: always run ls -la instead of ls. That first character — -, d, l, c, b, p, or s — tells you exactly what kind of object you're looking at. Pair it with the find command and sysadmin command cheat sheet for a powerful workflow.
LinuxTeck — A Complete Linux Infrastructure Blog
LinuxTeck covers everything from Linux fundamentals like file types and permissions to advanced system administration, kernel internals, DevOps pipelines, and cloud infrastructure. Explore our tutorials on shell scripting, networking, containers, server hardening, and more at linuxteck.com.