π File Types and Extensions
In Linux, everything is a file β yes, everything. Not just your text documents, but also your devices, directories, even your hardware! It's like a giant filing cabinet where every single thing inside (folders, text files, printers, disks, etc.) has its own file label.
How Linux Handles File Types
Linux doesn't rely heavily on extensions (like .txt, .exe, .png) to know what a file is. Instead, it looks at the file's content and permissions. That's why a file without .txt can still be a text file β Linux just knows by checking inside.
file myphoto myphoto: JPEG image data
Like opening a mystery box β you look inside to see what's there, not just read the label.
Common File Types in Linux
| Type | Description | Example |
|---|---|---|
| π Regular files | Text, images, executables, etc. | .txt, .png, .sh |
| π Directory files | Containers holding other files | /home, /etc |
| π Symbolic links | Shortcuts pointing to other files/folders (symlinks) | shortcut β /home/master/file.txt |
| βοΈ Device files | Represent hardware (e.g., disk, USB) | /dev/sda, /dev/tty |
| π¬ Socket files | Enable communication between processes | /var/run/docker.sock |
| π¨ Named pipes | Used for inter-process communication (FIFOs) | /tmp/my_pipe |
Think of each type like a role in a company β text files are employees (doing work), directories are departments, symlinks are signposts, and devices are machines.
File Extensions (Optional but Useful)
Even though Linux doesn't need them, humans do β they help us quickly recognize file types.
| Type | Example | Description |
|---|---|---|
| π Text | .txt, .log, .cfg, .conf | Plain text or config files |
| π» Script | .sh, .py, .pl, .rb | Executable scripts (Bash, Python, etc.) |
| π¦ Archive | .tar, .gz, .zip, .rar | Compressed file collections |
| π System | .service, .mount, .target | Used in Linux system configs |
| π· Image | .png, .jpg, .svg | Graphic files |
| π§ Executable | no extension | Binary or script you can run directly |
Here, install.sh is a script (sh = shell script).
Hidden Files
Any file or folder that starts with a dot (.) is hidden by default.
Examples:
- .bashrc
- .profile
- .gitconfig
To see them, use:
Like files tucked inside a hidden drawer β not gone, just out of sight until you look for them. These usually store user settings and configurations.
Executable Files
Some files can be run as programs if they have execute permissions.
To make a file executable:
Then run it:
Like giving a key to a person β only then can they open the door (execute the task).
Checking File Details
To view file details (type, size, permissions):
-rwxr-xr-- 1 master users 1204 Oct 25 2025 script.sh
Here's what it means:
- - β regular file
- rwxr-xr-- β permissions
- master β owner
- 1204 β size in bytes
- script.sh β file name
Real-Life Pro Tip
Linux doesn't care if you rename photo.jpg to photo.txt β it still knows it's an image internally. So, use the file command to check real types when in doubt.
Summary Snapshot
- Linux β "everything is a file."
- Extensions β optional, not mandatory.
- Use file command β to identify type.
- Hidden files β start with .
- Make files executable β with chmod +x .
Real-life analogy
Think of Linux file types like different categories in a library:
π Regular files β The actual books (text files, images, etc.)
π’ Directories β The shelves and sections organizing the books
π Symbolic links β The index cards pointing to where books are located
βοΈ Device files β The library machines (printers, computers, scanners)
π¬ Socket files β The intercom system connecting different library departments
π¨ Named pipes β The pneumatic tubes for sending requests between floors
Each serves a specific purpose in the library's organization system!