Linux is a powerful and structured operating system with a unique file system hierarchy and a robust set of commands for file management. This post documents what I've learned about the Linux file system, methods to create files, and essential commands to manipulate them.
1. File System Hierarchy
Linux organizes files in a hierarchical structure, starting from the root directory (/
). This differs from Windows, which uses drive letters (e.g., C:\
).
Windows File System:
Root Directory:
C:\
Common Subdirectories:
Program Files
Users
Program Files (x86)
PerfLogs
Logs
Linux File System:
Root Directory:
/
Important Subdirectories:
/home
– Home directory for users./root
– Home directory for the root (admin) user./etc
– Configuration files./usr
– Default software installation directory./bin
– Essential commands for all users./sbin
– Commands used by root users./opt
– Optional software packages./dev
– Device files representing hardware (e.g., disks, USB devices).
2. Essential File Commands in Linux
The cat
Command
The cat
command is one of the most universal tools in Linux. Despite its simplicity, all it does is copy standard input to standard output, making it incredibly versatile.
What You Can Do with cat
:
Create a file
cat > file1 [Write data here] Ctrl+D # Save and exit
Concatenate multiple files
cat file1 file2 > merged_file
Copy content from one file to another
cat file1 > file2
Use
tac
(reverse cat) to display file content from bottom to toptac file1
The touch
Command
The touch
command is a simple yet powerful way to create files and manage timestamps.
What You Can Do with touch
:
Create an empty file
touch file1
Create multiple empty files
touch file1 file2 file3
Change all timestamps (access & modify time)
touch -m file1
Update access time without modifying content
touch -a file1
What Are Timestamps?
Access Time (
atime
) – Last time the file was accessed.Modify Time (
mtime
) – Last time the file content was modified.Change Time (
ctime
) – Last time when file metadata was changed.
The vi
and nano
Editors
Both vi
and nano
are text editors in Linux, but they have some key differences.
vi
Editor
Universally available – Comes pre-installed in all Linux distributions.
Modes: Command mode and Insert mode.
Common Commands:
vi file1 # Open file in vi i # Switch to insert mode Esc # Exit insert mode :w # Save file :q # Quit editor :wq # Save and quit :q! # Quit without saving
nano
Editor
Easier to use – More intuitive, but not always pre-installed.
Common Commands:
nano file1 # Open file in nano Ctrl+O # Save file Ctrl+X # Exit editor Ctrl+K # Cut text Ctrl+U # Paste text
Wrapping Up
This exploration of Linux file management and commands has provided a solid foundation for understanding how files and directories work in a Linux environment. Each command serves a distinct purpose and can be combined in different ways to manage files efficiently.
🔹 Next Steps: I will be working on how to access and manage Linux using an EC2 instance on AWS.—-Stay tuned!