File Systems and Permissions
File system knowledge separates junior from senior candidates. Let's cover what interviewers expect you to know.
File System Concepts
Inodes
An inode stores metadata about a file:
# View inode information
ls -li /path/to/file
stat /path/to/file
# Inode contents:
# - File type and permissions
# - Owner (UID) and group (GID)
# - Size and timestamps
# - Pointers to data blocks
# - Link count
# NOTE: Does NOT contain the filename!
Interview question: "Disk shows space available but you can't create files. What happened?"
Answer: The file system ran out of inodes. Check with
df -i. Each file/directory consumes one inode. Common with many small files. Solutions: delete files, or reformat with more inodes.
Hard Links vs Soft Links
| Feature | Hard Link | Soft Link (Symlink) |
|---|---|---|
| Inode | Same as original | Different inode |
| Cross filesystem | No | Yes |
| Target deleted | Still works | Broken link |
| Directories | No (except . and ..) | Yes |
# Create hard link
ln original hardlink
# Create soft link
ln -s original symlink
# Check link count (second column)
ls -l
Common File Systems
| File System | Use Case | Key Feature |
|---|---|---|
| ext4 | General Linux | Journaling, mature |
| XFS | Large files, RHEL default | Scalable, parallel I/O |
| Btrfs | Snapshots, RAID | Copy-on-write |
| tmpfs | RAM-backed | Fast, volatile |
| NFS | Network shares | Distributed |
| overlay | Containers | Layered (Docker) |
Linux Permissions
Basic Permissions (rwx)
# Permission string: -rwxr-xr-x
# Type: - (file), d (directory), l (link)
# Owner: rwx (read, write, execute)
# Group: r-x (read, execute)
# Others: r-x (read, execute)
# Numeric: 755
# r=4, w=2, x=1
# rwx = 4+2+1 = 7
# r-x = 4+0+1 = 5
Special Permissions
| Permission | Symbol | Octal | Effect |
|---|---|---|---|
| SUID | s (user x) | 4000 | Execute as file owner |
| SGID | s (group x) | 2000 | Execute as group / inherit group |
| Sticky | t (other x) | 1000 | Only owner can delete |
# Set SUID (run as root)
chmod u+s /path/to/file
chmod 4755 /path/to/file
# Set sticky bit on /tmp (only owner can delete)
chmod +t /tmp
chmod 1777 /tmp
Interview question: "What's SUID and when is it dangerous?"
Answer: SUID allows a program to run with the owner's permissions. Dangerous when set on root-owned binaries—if exploited, attackers get root. Classic example: a vulnerable SUID binary leading to privilege escalation. Find SUID files:
find / -perm -4000 2>/dev/null
Disk Management Commands
Essential Commands
# Disk usage by directory
du -sh /var/*
# Largest files
find /var -type f -exec du -h {} + | sort -rh | head -20
# Disk space
df -h
# Disk I/O statistics
iostat -x 1
# Check disk health
smartctl -a /dev/sda
LVM Basics
Logical Volume Management allows flexible disk management:
Physical Volumes (PV) → Volume Groups (VG) → Logical Volumes (LV)
# Extend a logical volume
lvextend -L +10G /dev/vg0/lv_root
resize2fs /dev/vg0/lv_root # For ext4
xfs_growfs /dev/vg0/lv_root # For XFS
Interview Scenarios
Q: "A developer says they can't write to /var/log/app. How do you troubleshoot?"
# Check permissions
ls -la /var/log/app
# Check ownership
stat /var/log/app
# Check disk space
df -h /var/log
# Check inodes
df -i /var/log
# Check if filesystem is read-only
mount | grep /var
# Check SELinux (if enabled)
ls -Z /var/log/app
getenforce
Q: "Disk is at 100% but du -sh / shows only 60% used. Why?"
Possible causes:
- Deleted files still open:
lsof +L1shows files deleted but held open - Reserved space: ext4 reserves 5% for root by default
- Different mount points:
dumay not cross mount boundaries
# Find deleted files still open
lsof +L1
# Check reserved space
tune2fs -l /dev/sda1 | grep "Reserved block count"
Next, we'll dive into networking—TCP/IP and DNS are interview essentials. :::