목. 7월 24th, 2025

Linux handles files differently than Windows or macOS. While file extensions like .txt or .jpg exist, they’re not mandatory for determining file types. Let’s explore how Linux categorizes files and uses extensions.


📁 1. Linux File Types (The Core Seven)

In Linux, every file has a type indicated by the first character in ls -l output:

Symbol File Type Description Example Command
- Regular File Standard files (text, images, binaries) ls -l file.txt
d Directory Folder containing other files ls -ld Documents/
l Symbolic Link Shortcut pointing to another file/directory ln -s target link
c Character Device Hardware devices (keyboard, serial ports) ls -l /dev/ttyS0
b Block Device Storage devices (hard drives, USB) ls -l /dev/sda
p Named Pipe Inter-process communication (FIFO buffers) mkfifo mypipe
s Socket Network communication between processes ss -lnp

Linux file types shown in terminal


🔤 2. File Extensions in Linux (Convention, Not Requirement)

Unlike Windows, Linux doesn’t rely on extensions to determine file types. Extensions exist primarily for:

  • Human readability
  • Associating files with applications
  • Script organization

Common Extensions:

  • .sh → Shell script (chmod +x script.sh)
  • .py → Python script (python3 script.py)
  • .gz, .zip, .tar → Compressed archives
  • .conf → Configuration files (/etc/*.conf)
  • .log → Log files (/var/log/*.log)

File extensions in Linux file manager


🔍 3. How Linux Identifies File Types

Linux uses magic numbers (file signatures) to detect types:

file document.pdf  # Output: "PDF document"
file unknownfile   # Checks content regardless of extension

Key Tools:

  • ls -l → View file type symbols
  • file → Detect file type by content
  • stat → Show detailed file metadata

⚠️ 4. Special Cases to Note

  1. Executable Files:
    No .exe needed! Use chmod +x file to make scripts executable.

  2. Hidden Files:
    Start with . (e.g., .bashrc). View with ls -a.

  3. Extensionless Files:
    Common for binaries (e.g., /bin/ls) and scripts.


💡 Key Takeaways

  1. Linux file types are defined by metadata, not extensions.
  2. Extensions are human-friendly conventions.
  3. Always use file when unsure about a file’s type.
  4. Permissions matter more than extensions for executability.

> 💻 Try This!
> Run ls -l /dev to see device files, or create a symlink:
> ln -s real_file.txt shortcut_link

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다