Linux Navigation
Practice moving around the Linux command line with pwd, ls, cd, tree, file, which, whereis, man, and help.
Why Navigation Skills Matter
Before you can manage files, edit configs, or inspect logs, you need to know where you are and how to move around. Linux navigation commands are simple, but they form the foundation of almost every admin or DevOps task.
A common production workflow might involve jumping from a service config in /etc, to a binary in /usr/bin, to logs in /var/log, all within a few minutes.
Finding Your Current Location with pwd
The pwd command means print working directory. It shows your current location in the filesystem.
pwd
/home/devops/projects/api
This matters because many commands use relative paths. If you are in the wrong directory, the same command may fail or affect the wrong file.
Listing Files with ls
The ls command lists directory contents.
ls
ls -l
ls -la
ls -lh
Useful flags:
-lshows a long listing format-aincludes hidden files like.bashrc-hshows readable sizes such as4Kor12M
Example:
ls -lah /etc/nginx
This shows permissions, owners, sizes, and hidden entries inside /etc/nginx.
Tip: Hidden files in Linux usually start with a dot, such as
.gitignoreor.env.
Changing Directories with cd
The cd command means change directory.
cd /var/log
cd ..
cd ~
cd -
Useful patterns:
cd ..goes up one levelcd ~goes to your home directorycd -returns to the previous directory
A real example:
cd /etc
cd nginx
cd ../ssh
This is faster than typing every full path from scratch.
Visualizing Structure with tree
The tree command shows a directory as a tree structure.
tree
tree -L 2 /etc
-L 2 limits output to two levels deep, which keeps things readable.
If tree is not installed on a system, that is normal. Many minimal servers do not include it by default.
Identifying File Types with file
The file command tells you what a file actually is.
file /bin/bash
file /etc/hosts
file app.tar.gz
This is helpful when extensions are missing or misleading. A file called backup could be plain text, a gzip archive, or a binary.
Locating Commands with which and whereis
which shows the executable path that your shell will run.
which bash
which python3
Example output:
/usr/bin/bash
whereis looks more broadly for a command’s binary, source, and manual pages.
whereis bash
whereis ssh
Use which when you want the exact command path the shell uses. Use whereis when you want extra related locations.
Reading Documentation with man
The man command opens manual pages.
man ls
man chmod
Manual pages explain syntax, options, and behavior. They are one of the best ways to learn Linux directly from the system.
Search inside a man page by typing /pattern and press q to quit.
Note: Some containers and tiny images do not include man pages to save space.
Using Built-In Help with help
The help command explains shell built-ins.
help cd
help pwd
This is different from man. Commands like cd are often shell built-ins, so help may be more accurate than man for them.
A Small Hands-On Workflow
Imagine you need to inspect an application directory:
pwd
ls -lah
cd /opt/myapp
tree -L 2
file deploy.sh
which bash
man grep
This workflow answers several questions quickly:
- where am I?
- what files are here?
- what is the directory structure?
- what type of file is this?
- which shell binary will run?
- where can I learn more about a command?
Common Beginner Mistakes
Forgetting the Current Directory
Running rm config.yaml is risky if you are not sure where you are. Use pwd first.
Ignoring Hidden Files
Beginners often use ls and assume nothing else exists. But .env, .ssh, and .git are hidden unless you include -a.
Not Reading Built-In Docs
Guessing flags is slower than using man or help. Linux rewards curiosity.
Test Your Understanding
Let's see how well you understood the concepts! These exercises will help reinforce what you just learned.
Exercise 1: Listing hidden entries
Scenario: You suspect a directory contains .env and .bashrc files that plain ls does not show.
Question: Which command flag from the lesson should you add?
Exercise 1: Listing hidden entries
Choose the ls option that reveals dotfiles and other hidden entries.
Exercise 2: Choosing which versus whereis
Question: If you want the exact executable path your shell will run for python3, which command is the best fit?
Exercise 2: Choosing which versus whereis
Pick the command that shows the executable path your shell will use.
Exercise 3: Getting help for built-ins
Question: Why did the tutorial recommend help cd instead of relying only on man cd?
Exercise 3: Getting help for built-ins
Identify why the help command can be more accurate for cd.