Centos 7 change directory commands
Enjoying this content? Subscribe to the Channel!
Mastering the Linux File System: A Beginner’s Guide to Essential Navigation Commands
Welcome to Darren’s Tech Tutorials! If you’re serious about using Linux—whether it’s for server administration, development, or just everyday computing—the first crucial skill you must master is file system navigation.
The command line is the heart of Linux, and knowing how to move around quickly and efficiently can dramatically boost your productivity. Don’t worry; it’s much simpler than it sounds!
In this comprehensive guide, we are going to walk step-by-step through the most fundamental commands required to navigate the Linux file system like a pro. While we’re demonstrating these commands using the powerful CentOS 7 operating system, the best part is that these principles and commands work exactly the same way across virtually every Linux distribution (Ubuntu, Fedora, Debian, etc.).
By the end of this tutorial, you will be an expert in:
- Changing your directory location (
cd). - Identifying your current location (
pwd). - Listing and viewing directory contents (
ls). - Quickly switching between your current and previous locations (
cd -).
Let’s dive right into the terminal!
Knowing Your Location: The pwd Command
Before you can confidently start moving around the file system, you need to know exactly where you are. This is where the simple, yet essential, pwd command comes into play.
pwd stands for Print Working Directory.
When you execute this command, the system prints the full, absolute path of the directory you are currently sitting in. This is incredibly helpful, especially when dealing with nested folders or troubleshooting path issues.
How to use it:
$ pwd
/home/darren/documents
If you ever feel lost in the terminal, just remember to type pwd to reorient yourself!
Changing Your Location: The Power of cd
The cd command, short for Change Directory, is the engine of Linux navigation. This is how you move from one folder to the next.
The cd command is versatile and has several crucial usage patterns you need to know:
1. Moving to a Specific Path
To move directly into a subdirectory or a completely different location, you simply provide the path after the command.
# Move into the 'tutorials' subdirectory from your current location
$ cd tutorials
# Move using an absolute path (starting from the root '/')
$ cd /var/log/apache
2. Moving Up One Level
To navigate back to the parent directory (the directory containing your current one), you use the special notation .. (dot dot).
# If you are in /home/darren/documents, this moves you back to /home/darren
$ cd ..
3. Returning to Your Home Directory
This is one of the biggest time-savers! No matter where you are in the file system, if you want to immediately jump back to your user’s home directory (/home/darren in this example), you have two quick options:
# Option A: Simply type 'cd' with no arguments
$ cd
# Option B: Use the tilde (~) symbol
$ cd ~
Exploring What’s Inside: The Versatile ls Command
Now that you know how to move (cd) and how to confirm where you are (pwd), the next logical step is to see what files and folders are actually in the directory you’ve arrived at. This is the job of the ls command, which stands for List.
Running ls by itself will give you a quick, clean list of contents:
$ ls
images scripts notes.txt setup.sh
To gain real insight, however, you need to start using switches, or “flags,” with the ls command.
Essential ls Switches
| Command | Description |
|---|---|
ls -l |
Provides a long list format, showing permissions, owner, group, size, and modification date. This is arguably the most common way to use ls. |
ls -a |
Lists all files and directories, including hidden ones (those that start with a dot, like .bashrc). |
ls -lh |
Combines the long list (-l) with the human-readable format (-h), converting file sizes from bytes into kilobytes (K), megabytes (M), etc. |
For maximum detail and readability, combine them:
$ ls -lah
The Instant Jump: Switching Between Directories
Here’s a fantastic trick that veterans use constantly: switching quickly between the directory you are currently in and the directory you were just in. Think of this as the “back button” for your Linux terminal session.
This is achieved using the cd command followed by a hyphen (-).
Scenario:
- You are working in your home directory:
/home/darren. - You jump deep into system logs:
cd /var/log/apache2. - You immediately realize you need a file back in your home directory.
Instead of typing the long path again, just use:
$ cd -
/home/darren
This command instantly switches you back to the previous location, saving valuable time and keystrokes!
Conclusion and Further Resources
Congratulations! You now have the four essential building blocks for moving confidently around any Linux system. These commands (pwd, cd, ls, and cd -) are the foundation of all command-line work. Practice them regularly, and navigating the Linux file system will quickly become second nature.
We encourage you to open your terminal right now and start experimenting with changing directories and listing contents!
Need the Commands Written Down?
You can find a complete cheatsheet of the commands used in this tutorial and more on the blog post accompanying the video:
🔗 Command Cheatsheet: http://darrenoneill.eu/?p=335
New to Linux?
If you are just getting started and want to follow along with the same setup we used, you can find our tutorial on installing the CentOS 7 operating system here:
▶️ Install CentOS 7: https://youtu.be/qZXZepdUjRI
If you found this guide helpful, be sure to subscribe to Darren’s Tech Tutorials for more clear, practical, and enthusiastic tech guides just like this one! Happy navigating!