Linux file types
Linux File Types and How to Create Them
| File Type | Symbol | Description | How to Create |
|---|---|---|---|
| Regular File | - |
Ordinary files (text, binaries, images, etc.) | touch filename or echo "text" > filename |
| Directory | d |
Contains other files/directories | mkdir dirname |
| Symbolic Link | l |
Shortcut or reference to another file or directory | ln -s target linkname |
| Block Device File | b |
Represents devices that transfer data in blocks (e.g., hard drives) | sudo mknod filename b major minor |
| Character Device File | c |
Represents devices that transfer data character by character (e.g., tty) | sudo mknod filename c major minor |
| Socket | s |
Used for inter-process communication (network or local sockets) | In code: socket() syscall; From shell: nc -lU socketfile (creates a UNIX socket file) |
| FIFO (Named Pipe) | p |
Special file for inter-process communication (first-in, first-out) | mkfifo filename |
| File Type | How to Create Example | Write Example | Read Example | Notes |
|---|---|---|---|---|
| Regular File | touch file.txtecho "data" > file.txt |
echo "hello" > file.txt |
cat file.txt |
Most common file type |
| Directory | mkdir mydir |
Cannot write data directly | ls mydir |
Holds other files/directories |
| Symbolic Link | ln -s target symlink |
echo "hi" > symlink (writes to target) |
cat symlink |
Shortcut to another file |
| Block Device | sudo mknod /dev/myblock b 8 0 |
sudo dd if=file.img of=/dev/myblock |
sudo dd if=/dev/myblock of=file.img |
Represents disks, partitions, etc. |
| Character Device | sudo mknod /dev/mychar c 4 64 |
echo "A" > /dev/mychar |
cat /dev/mychar |
Serial ports, terminals, etc. |
| FIFO (Named Pipe) | mkfifo mypipe |
echo "msg" > mypipe |
cat mypipe |
Used for inter-process communication |
| Socket | Created by programs or nc -lU /tmp/mysock |
“msg” | nc -U /tmp/mysock` | nc -lU /tmp/mysock |
