Linux is known for its powerful file system and command-line tools. Whether you're an aspiring DevOps engineer or just curious about Linux internals, understanding the file system is foundational.
In this guide, we'll explore everything from the Linux file hierarchy to file manipulation commands.
📁 1. What is the Linux File System?
The Linux file system is a structured arrangement for storing and organizing data. Everything in Linux is treated as a file, whether it’s a document, directory, or hardware device.
🌲 2. File Hierarchy System
Linux follows a hierarchical file structure starting from the root directory /
.
/
├── bin/ → Essential user binaries
├── boot/ → Boot loader files
├── dev/ → Device files
├── etc/ → Configuration files
├── home/ → User directories
├── lib/ → Essential shared libraries
├── tmp/ → Temporary files
├── usr/ → User programs
├── var/ → Variable data (logs, spool)
🛣️ 3. Absolute vs Relative Path
📌 Absolute Path
An absolute path always starts from the root directory / and points to a file or directory regardless of the current working directory.
/home/username/docs/file.txt
📌 Relative Path
A relative path starts from the current directory (denoted by .) and is relative to where you are in the filesystem.
./docs/file.txt
🔗 4. Hard Links, Inodes, and Symbolic Links
📦 Inodes:
Every file has an inode storing metadata (permissions, size, timestamps, etc.)
🔁 Hard Link:
Creates another name pointing to the same inode.
ln original.txt hardlink.txt
🔗 Symbolic (Soft) Link:
Points to the file path, not the inode.
ln -s original.txt symlink.txt
🛠️ 5. Useful File System Commands
📄 ls – List Files
ls -l # Long listing
ls -a # Include hidden files
🕒 atime, mtime, ctime
atime: Last accessed
mtime: Last modified
ctime: Last changed (metadata)
Check using:
stat filename
Update time using:
touch filename
Check date/time:
date
🔃 Sorting Files
ls -lt # Sort by modified time
ls -lSr # Sort by size, reverse
🐈 File Viewing: cat, less, tail, head, watch
cat file.txt
less file.txt
tail -f file.txt # Follow file
head -n 10 file.txt
watch -n 2 ls -l # Refresh every 2s
📂 Create Files & Dirs: touch, mkdir
touch newfile.txt
mkdir newfolder
✂️ File Ops: cp, mv, rm, shred
cp file1.txt backup/
mv file.txt renamed.txt
rm unwanted.txt
shred -u sensitive.txt # Secure delete
🔗 Pipes and Word Count: |, wc
cat file.txt | wc -l
➕ Redirection: >, >>, 2>, &>, cut, tee
echo "Hello" > file.txt # Overwrite
echo "World" >> file.txt # Append
command 2> error.log # Errors only
command &> all.log # Stdout + stderr
cut -d':' -f1 /etc/passwd
command | tee output.log # View + save
🔍 which & plocate
which bash
plocate file.txt
🔎 find with exec
find . -name "*.log" -exec rm {} \;
🔍 grep – Search Text
grep "error" logfile.txt
🔤 strings – Extract printable text from binary
strings binaryfile
🔁 Compare Files: cmp, diff, sha256sum
cmp file1.txt file2.txt
diff file1.txt file2.txt
sha256sum file.txt
✍️ VIM Editor Basics
Open file:
vim file.txt
Common commands:
i: Insert mode
Esc: Exit insert
:w: Save
:q: Quit
:wq: Save and quit
📦 Archiving: tar and gzip
Create archive:
tar -cvf archive.tar folder/
Extract:
tar -xvf archive.tar
Compress:
gzip file.txt
gunzip file.txt.gz
🔚 Conclusion
The Linux file system is a powerful and flexible system, and the commands above will help you navigate and control it like a pro. If you're pursuing DevOps, mastering these tools is essential.