Master Linux CLI: Your First 5 Hands-On Commands
Unlock the power of your Linux system with these five fundamental command-line interface commands, taught through practical, hands-on exercises.
The Linux command line interface (CLI) might seem daunting at first glance. No graphical interface, just a blinking cursor, waiting for your instructions. But mastering the CLI is one of the most powerful skills you can acquire, opening doors to efficient system management, development, and even Cloud Computing with AWS: Deploy Your First App.
Whether you're setting up a development environment, deploying an application, or exploring Cybersecurity Fundamentals: Think Like an Attacker, the terminal is your direct line of communication with the operating system. It's why Linux is a trending topic, with learners on Tully exploring its capabilities.
This article will get you started with five essential Linux commands, transforming that blank screen into a canvas for your control. Get ready to dive in and feel the immediate feedback of working directly with your system.
1. Where Am I? (pwd)
When you first open your terminal, it's like stepping into a new room. The first thing you want to know is where you are. The pwd (Print Working Directory) command tells you exactly that.
Purpose: Displays the absolute path of your current directory. Syntax: ``bash pwd `` Exercise:
- Open your terminal.
- Type
pwd and press Enter.
What you'll see: You'll get an output similar to /home/yourusername or /Users/yourusername (on macOS, which is Unix-based and uses similar commands). This path is your current location within the file system hierarchy.
2. What's Here? (ls)
Now that you know where you are, you'll want to see what's around. The ls (list) command shows you the contents of your current directory.
Purpose: Lists files and directories within a specified path (or current directory if none is given). Syntax: ``bash ls ls -l ls -a ls -la `` Exercise:
- From your home directory (where you executed
pwd), type ls and press Enter. You'll see files and folders in your home directory. - Try
ls -l for a "long listing" format, showing more details like permissions, owner, size, and modification date. - Then, use
ls -a to show all files, including hidden ones (those starting with a dot, like .bashrc). - Combine them with
ls -la.
What you'll see: A list of files and directories. With options like -l, you get detailed information. Hidden files, often configuration files, become visible with -a.
3. Moving Around (cd)
The file system is a tree structure, and cd (change directory) is how you navigate through its branches.
Purpose: Changes your current working directory. Syntax: ``bash cd <directory_name> cd .. cd ~ `` Exercise:
- From your home directory, identify a directory you saw with
ls (e.g., Documents). Type cd Documents and press Enter. - Use
pwd again to confirm your new location. - To go back up one level, type
cd .. and press Enter. Use pwd to confirm you're back in your home directory. - To return to your home directory from anywhere, simply type
cd ~ or just cd.
What you'll see: Your prompt might change to reflect your new directory, and pwd will confirm the path. This command is fundamental for navigating your system effectively, a skill deeply explored in the Linux Command Line Mastery: The Terminal, Files, and Shell Scripting course.
4. Creating Space (mkdir)
To organize your work, you'll often need to create new directories. mkdir (make directory) does exactly that.
Purpose: Creates new directories. Syntax: ``bash mkdir <new_directory_name> `` Exercise:
- Navigate to your home directory (
cd ~). - Type
mkdir my_project and press Enter. - Use
ls to verify that my_project now appears in your home directory. - You can also create multiple directories at once:
mkdir project1 project2. - Or even nested directories with
-p: mkdir -p project_x/data/raw.
What you'll see: The new directory (or directories) will appear in the output of ls. This is how you begin to structure your files for any project, from web development to data analysis.
5. Cleaning Up (rm and rmdir)
Eventually, you'll need to remove files or directories that are no longer needed. The rm (remove) and rmdir (remove directory) commands handle this.
Caution: rm is powerful and doesn't usually send items to a trash bin. Deleted files are gone. Double-check your commands!
Purpose: rm deletes files. rmdir deletes empty directories. Syntax: ``bash rm <filename> rm -r <directory_name> # For non-empty directories rmdir <empty_directory_name> `` Exercise:
- Navigate into the
my_project directory you created (cd my_project). - Create an empty file:
touch test_file.txt. - Use
ls to see test_file.txt. - Now, delete it:
rm test_file.txt. - Use
ls again to confirm it's gone. - Go up one level (
cd ..). - Try
rmdir my_project. This will only work if my_project is empty. If it's not, you'll get an error. - If
my_project wasn't empty, you'd use rm -r my_project to delete the directory and its contents recursively. Only do this if you're certain you want to delete everything inside my_project!
What you'll see: Files and directories disappear from ls output. While powerful, rm is an essential tool for maintaining a clean and organized file system.
Your Linux Journey Has Begun
You've just taken your first significant steps into the Linux command line! With these five commands, you can orient yourself, explore, navigate, create, and manage your file system with newfound efficiency. This hands-on practice is the core of effective learning, a principle we champion across our 47 public courses on Tully.
Ready to deepen your expertise? Explore the Linux topic hub for more ways to enhance your command-line skills. Or, dive into one of the 8 technical courses available to Tully learners.
Start your next learn-by-doing course on Tully today.
Start learning on Tully Courses — learn anything by doing it.