Linux Basics
Navigating the File System
The first thing you need when you land on a Linux server is orientation. Where am I? What is around me? How do I move around? This page covers the three most fundamental commands in Linux: pwd, ls, and cd. These are the commands you will use more than any others, every single time you touch a Linux system.
After this page, you should be able to:
- Identify your current location in the file system
- List files and directories, including hidden files
- Read and interpret the output of
ls -la - Move between directories using absolute and relative paths
- Recognize the purpose of key system directories
pwd — Where Am I?
pwd stands for print working directory. It tells you exactly where you are in the file system right now. Run it:
pwd
You should see something like:
/home/azureuser
This is your home directory. When you SSH into a Linux machine, this is where you land by default. The path /home/azureuser means you are in the azureuser folder, which is inside the home folder, which is at the root (/) of the entire file system.
You will use pwd constantly. When you have been jumping between directories and are not sure where you ended up, pwd is your anchor. It is also useful in scripts when you need to know the current working directory.
ls — What Is Around Me?
ls stands for list. It shows you the contents of a directory — the files and folders that are in your current location (or any location you specify).
Basic ls
Running ls by itself shows the names of visible files and directories:
ls
On a fresh Ubuntu VM, your home directory might be empty. That is normal. You will see more interesting output when you navigate to system directories.
ls -l (Long Format)
The -l flag gives you the detailed view. This is where the real information lives:
ls -l
Example output:
drwxr-xr-x 2 azureuser azureuser 4096 Mar 15 10:22 Documents -rw-r--r-- 1 azureuser azureuser 220 Mar 15 09:01 .bash_logout -rw-r--r-- 1 azureuser azureuser 3771 Mar 15 09:01 .bashrc
Each column means something specific. Here is how to read it:
drwxr-xr-x— Permissions. The first character tells you the type:dmeans directory,-means regular file. The remaining 9 characters are read/write/execute permissions for the owner, group, and everyone else. You will learn more about this in the Permissions page.2— Number of hard links. For directories this includes.(itself) and..(parent). You can mostly ignore this column for now.azureuser(first) — Owner. The user who owns this file.azureuser(second) — Group. The group that owns this file.4096— Size in bytes. For directories this is the directory entry size, not the total size of the contents.Mar 15 10:22— Last modified date and time.Documents— Name. The file or directory name.
ls -a (All Files, Including Hidden)
In Linux, any file or directory whose name starts with a dot (.) is hidden. These are typically configuration files. The -a flag shows everything, including hidden files:
ls -a
You will notice entries like . (current directory), .. (parent directory), .bashrc, .profile, and .ssh. These are not junk — they are configuration files that control how your shell and tools behave.
ls -la (The Combo You Will Use 90% of the Time)
Combining -l and -a gives you the full picture: all files, with full details. This is the most commonly used form of ls in real work:
ls -la
Example output:
total 28 drwxr-x--- 4 azureuser azureuser 4096 Mar 15 10:22 . drwxr-xr-x 3 root root 4096 Mar 15 09:00 .. -rw------- 1 azureuser azureuser 123 Mar 15 10:30 .bash_history -rw-r--r-- 1 azureuser azureuser 220 Mar 15 09:01 .bash_logout -rw-r--r-- 1 azureuser azureuser 3771 Mar 15 09:01 .bashrc drwx------ 2 azureuser azureuser 4096 Mar 15 09:05 .ssh -rw-r--r-- 1 azureuser azureuser 807 Mar 15 09:01 .profile
Get comfortable reading this output. You will see it hundreds of times.
Other Useful Flags
ls -lh— Human-readable sizes. Instead of4096, you will see4.0K. Instead of1048576, you will see1.0M. Very helpful for log files and large directories.ls -lt— Sort by modification time, newest first. Useful when you want to see what changed most recently on a server.ls -lah— Combines all three: long format, all files, human-readable sizes. A popular choice.
cd — Moving Around
cd stands for change directory. It moves you from one location to another in the file system. Here are the forms you need to know:
cd /var/log— Absolute path. Takes you directly to/var/logno matter where you currently are. An absolute path always starts with/.cd Documents— Relative path. Moves into a directory calledDocumentsthat is inside your current location. If it does not exist, you will get an error.cd ..— Up one level. Moves to the parent directory. If you are in/home/azureuser, this takes you to/home.cd ~— Home directory. Takes you back to your home directory from anywhere. The tilde (~) is a shortcut for/home/your-username.cd -— Previous directory. Takes you back to wherever you were before your lastcdcommand. This is extremely useful when you are jumping between two directories.cd(no arguments) — Home directory. Same ascd ~. Runningcdwith nothing after it takes you home.
Try this sequence to see how each one works:
pwd # See where you are cd /var/log # Go to the log directory pwd # Confirm you moved cd ~ # Go back home pwd # Confirm you're home cd - # Jump back to /var/log pwd # Confirm you're back in /var/log cd .. # Go up one level to /var pwd # Confirm you're in /var
Key Directories You Should Know
Linux has a standard directory structure. No matter what distribution you are on, these directories exist and serve the same purpose. Here are the ones you will interact with most as an IT professional:
/home — User Home Directories
Each user gets a folder here. Your home is /home/azureuser. Personal files, shell configuration, and SSH keys live here.
/var/log — System and Application Logs
This is one of the most important directories on any server. When something breaks, this is where you look first. Files like syslog, auth.log, and kern.log live here and contain records of everything happening on the system.
/etc — Configuration Files
Nearly every application and system service stores its configuration here. Network settings, user accounts, hostname, DNS resolver configuration, firewall rules — it is all in /etc. This is the second most important directory for troubleshooting.
/tmp — Temporary Files
Files here are usually cleared on reboot. Applications use this for scratch space. Anyone on the system can write here.
/usr — User Programs
Installed software, libraries, and documentation live under /usr. The commands you run (like ls and pwd) are typically in /usr/bin.
/root — Root User's Home
This is the home directory for the root user (the superuser / administrator). It is not inside /home — it is at the top level of the file system. Regular users cannot access it without elevated permissions.
Troubleshooting tip
When you are investigating a problem on a server, 90% of your time will be spent in two places: /var/log (reading what happened) and /etc (reading how things are configured). Learn to navigate to these quickly.
Try It — Your First Exploration
SSH into your VM and work through the following steps. Do not just read them — actually type each command and look at the output.
- Run
pwdto confirm you are in your home directory. - Run
ls -lato see all files in your home directory, including hidden configuration files. Read the output — look at the permissions, the owner, and the file names. - Navigate to the system log directory:
cd /var/log - Run
ls -lhto see the log files with human-readable sizes. Notice the different file sizes. Some logs are small; others can grow to megabytes or gigabytes on busy servers. - Look for familiar names:
syslog,auth.log,kern.log,dpkg.log. These are all standard Ubuntu log files. - Navigate to the configuration directory:
cd /etc - Run
lsto see the contents. There are a lot of files and directories here. Do not try to memorize them all — just get a sense of how much configuration lives in this one directory. - Navigate back home:
cd ~ - Confirm you are home:
pwd - Try
cd -to jump back to/etc, thencd -again to return home.
Do not be afraid to explore. You cannot break anything by looking around. Run ls in every directory you visit. The goal right now is to build a mental map of where things live on a Linux system.
Checkpoint
Before moving on, confirm you can do all of the following:
- Run
pwdand understand the output - Run
ls -laand identify each column in the output - Navigate to a specific directory using
cdwith an absolute path - Return home using
cd ~or justcd - Go back to a previous directory using
cd - - Go up one level using
cd .. - Name at least three important system directories and their purpose
If you are comfortable with all of the above, you are ready to move on. These three commands — pwd, ls, and cd — are the foundation for everything that follows.