π Mastering Linux Basics: Navigating, Listing & Managing Files Like a Pro (Day 2)
Table of contents
- Basic Linux Commands (File Listing, Navigation, and Directory Management)
Basic Linux Commands (File Listing, Navigation, and Directory Management)
Welcome to Day 2 of the 90 Days of DevOps journey! π Today, we dive into some essential Linux commands that will help you navigate the file system, list directories, and manage files efficiently. Whether youβre a beginner or just need a refresher, this guide will make Linux more approachable.
π 1. Understanding the Linux File System
Before jumping into commands, letβs understand how files and directories are organized in Linux:
π Everything in Linux is structured in a tree-like hierarchy with the root directory (/
) at the top.
π Inside the root, there are standard directories like:
/home
β Stores user files/etc
β Configuration files/bin
β System binaries (commands)/var
β Logs and variable data
Now, let's learn how to list files, navigate directories, and create folders! π―
π 2. Listing Files & Directories (ls
Command)
The ls
command is used to list files and directories inside a folder.
πΉ Basic Usage:
ls
- This will display all visible files and directories in the current folder.
πΉ Common ls
Options:
Command | Description |
ls -l | π Detailed list (permissions, size, date, owner) |
ls -a | π Show all files, including hidden ones (.filename ) |
ls -i | π’ Show inode numbers (unique ID for each file) |
ls -d */ | π List only directories (not files) |
ls *.sh | π List only .sh files (pattern matching) |
πΉ Example Output of ls -l
drwxr-xr-x 2 user user 4096 Feb 22 10:30 Documents
-rw-r--r-- 1 user user 1234 Feb 22 11:00 script.sh
d β Directory
rwx β Permissions (Read, Write, Execute)
1234 β File size (bytes)
Feb 22 11:00 β Last modified date
π Real-life Example: Imagine ls
as opening a folder on your computer and seeing all the files inside! ποΈ
π 3. Navigating Directories (cd
Command)
The cd
(change directory) command helps move between folders.
πΉ Basic Usage:
cd folder_name
- Moves into
folder_name
.
πΉ Common cd
Commands:
Command | Description |
cd /home/user | πΆββοΈ Go to a specific path |
cd .. | π Move one level back |
cd ../.. | ππ Move two levels back |
cd ~ or cd | π Go to home directory |
cd - | π Go back to the previous directory |
π Real-life Example: cd
is like clicking through folders on a Windows/Mac file explorer.
π 4. Finding Your Current Location (pwd
Command)
Want to check which folder you're in? Use:
pwd
π Output Example:
/home/user/Documents
This means youβre inside the Documents
folder of user user
.
π Real-life Example: Think of pwd
as looking at the address bar in Windows Explorer.
π 5. Creating Directories (mkdir
Command)
The mkdir
command is used to create new folders.
πΉ Basic Usage:
mkdir folder_name
- Creates a new directory named
folder_name
.
πΉ Advanced mkdir
Options:
Command | Description |
mkdir NewFolder | π Create a new folder |
mkdir .HiddenFolder | πΆοΈ Create a hidden folder (prefix . ) |
mkdir Folder1 Folder2 | π¦ Create multiple folders at once |
mkdir -p Parent/Child/Grandchild | π³ Create nested directories |
π Real-life Example: Creating a folder in File Explorer by right-clicking β New Folder.
π― Summary: What We Learned Today
β
ls
β List files and directories
β
cd
β Navigate between folders
β
pwd
β Show current directory path
β
mkdir
β Create new folders
These commands are essential for managing files in Linux, especially for DevOps, scripting, and system administration. Master these basics, and you'll navigate Linux like a pro! πͺπ§
π‘ Whatβs Next?
Stay tuned for Day 3, where we'll explore more advanced file handling and permissions in Linux! π
π Challenge: Try these commands on a Linux system and see the results for yourself! π»π₯
Would you like a hands-on practice assignment? Let me know! π