File_Structures

Overview of Linux hierarchical file system structure, directory organization, and filesystem concepts

The Linux file system is a hierarchical tree structure that organizes all files and directories. Understanding this structure is crucial for navigation, system administration, and file management in Linux environments.

Key Concepts

  • Root Directory (/): Top-level directory containing all others
  • Mount Points: Where filesystems attach to directory tree
  • Inodes: Data structures storing file metadata
  • File Types: Regular files, directories, links, devices
  • Permissions: Read, write, execute for user/group/other
  • Path Types: Absolute (from /) vs relative (from current)

Command Syntax

ls [options] [path] - List directory contents tree [options] [path] - Display directory tree file [options] filename - Identify file type stat filename - Show detailed file information

Common Options

-l - Long format with permissions/ownership -a - Show hidden files (starting with .) -h - Human readable file sizes -R - Recursive listing -i - Show inode numbers

Practical Examples

Example 1: Standard Directory Structure

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
/
├── bin/     # Essential user binaries
├── boot/    # Boot loader files
├── dev/     # Device files
├── etc/     # System configuration
├── home/    # User home directories
├── lib/     # Shared libraries
├── media/   # Removable media mount points
├── mnt/     # Temporary mount points
├── opt/     # Optional software packages
├── proc/    # Process information filesystem
├── root/    # Root user home directory
├── run/     # Runtime data
├── sbin/    # System binaries
├── srv/     # Service data
├── sys/     # System information
├── tmp/     # Temporary files
├── usr/     # User programs and data
└── var/     # Variable data files

Example 2: View file details

1
2
ls -la /etc/passwd
-rw-r--r-- 1 root root 2847 Oct 15 10:30 /etc/passwd

Shows permissions, ownership, size, and timestamp

Example 3: Check file type

1
2
file /bin/bash
/bin/bash: ELF 64-bit LSB executable

Identifies executable binary file

Example 4: Directory tree view

1
2
3
4
5
6
7
8
9
tree -L 2 /var/
/var/
├── cache/
│   └── apt/
├── lib/
│   └── dpkg/
├── log/
│   └── syslog
└── tmp/

Use Cases

  • System administration and maintenance
  • Software installation and configuration
  • User data organization
  • Security and permission management
  • Backup and recovery operations
  • Troubleshooting system issues

pwd - Print working directory cd - Change directory mkdir - Create directories rmdir - Remove empty directories find - Search for files and directories locate - Find files using database which - Locate command binaries whereis - Locate binaries, source, manuals

Tips & Troubleshooting

  • Use df -h to check filesystem usage
  • Hidden files start with dot (.)
  • /proc and /sys are virtual filesystems
  • Always use absolute paths in scripts
  • Be careful with case sensitivity
  • Use lsof to see open files
  • Check mount points with mount command
  • Avoid storing data in /tmp permanently
  • Use du -sh to check directory sizes
  • Remember / is filesystem root, not user root