Navigating: pwd, ls & cd
Three commands do most of the work of moving around Linux: pwd tells you where you are, ls shows what is here, and cd takes you somewhere else. You will type them hundreds of times a day, so it is worth learning their most useful options properly.
All examples use Priya's home folder, /home/priya, which contains a few folders and a CSV file of shop orders.
pwd: where am I?
The shell always has a current working directory, the folder that relative paths start from. pwd (print working directory) prints it as an absolute path:
pwd/home/priya
When you open a new terminal you start in your home folder. The prompt also shows the current folder (~ for home), but pwd gives the full path, which is useful in scripts and when the prompt is shortened.
ls: what is here?
ls lists the contents of a directory: the current one if you give no argument, or any directory you name.
ls
ls -F
ls projects/shop-siteDocuments Downloads notes orders.csv projects Documents/ Downloads/ notes/ orders.csv projects/ images index.html style.css
The -F option adds a / after directories (and a * after programs), which helps when your terminal has no colours. With colours on, directories usually appear in blue.
Reading the long listing
ls -l shows one line per entry with details. This is the view you will use most:
ls -ltotal 20 drwxrwxr-x 2 priya priya 4096 Oct 29 18:40 Documents drwxrwxr-x 2 priya priya 4096 Oct 27 09:12 Downloads drwxrwxr-x 2 priya priya 4096 Oct 30 08:05 notes -rw-rw-r-- 1 priya priya 281 Oct 30 08:15 orders.csv drwxrwxr-x 3 priya priya 4096 Oct 28 21:30 projects
Take the orders.csv line apart from left to right:
| Part | Meaning |
|---|---|
- | Type: - is a regular file, d a directory, l a symbolic link |
rw-rw-r-- | Permissions for owner, group and others (see Permissions & Ownership) |
1 | Number of hard links (for directories it grows with the number of subdirectories) |
priya priya | The owner and the group |
281 | Size in bytes |
Oct 30 08:15 | Last modified time (files older than six months show the year instead) |
orders.csv | The name |
The total line at the top is the disk space used, counted in 1 KB blocks. A directory itself always shows 4096 bytes on most filesystems; that is the size of its list of names, not of the files inside it.
Useful ls options
Options combine freely. These are worth remembering:
| Option | What it does |
|---|---|
-a | Show hidden entries (names starting with .) |
-h | Human-readable sizes (87K, 2.4M) with -l |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-r | Reverse the sort order |
-R | List subdirectories recursively |
-d | Show the directory itself, not its contents |
ls -lh Documents
ls -lt
ls -ld Documentstotal 104K -rw-rw-r-- 1 priya priya 16K Oct 29 18:40 marks-2026.xlsx -rw-rw-r-- 1 priya priya 87K Oct 29 18:38 resume.pdf total 20 -rw-rw-r-- 1 priya priya 281 Oct 30 08:15 orders.csv drwxrwxr-x 2 priya priya 4096 Oct 30 08:05 notes drwxrwxr-x 2 priya priya 4096 Oct 29 18:40 Documents drwxrwxr-x 3 priya priya 4096 Oct 28 21:30 projects drwxrwxr-x 2 priya priya 4096 Oct 27 09:12 Downloads drwxrwxr-x 2 priya priya 4096 Oct 29 18:40 Documents
The first command gives friendly sizes. The second puts the most recently changed item first, which is the quickest way to find "the file I just downloaded". The third shows the details of Documents itself rather than listing what is inside. A very common combination is ls -lah: everything, with details, in readable sizes.
cd: go somewhere else
cd (change directory) moves you. Give it an absolute or relative path:
cd projects/shop-site
pwd
cd ..
pwd
cd /var/log
pwd
cd
pwd/home/priya/projects/shop-site /home/priya/projects /var/log /home/priya
cd .. goes up one level. cd on its own (or cd ~) always takes you home, from anywhere. Two more shortcuts are handy: cd - jumps back to the previous directory you were in and prints it, and cd / goes to the very top of the tree.
Press Tab while typing a path and Bash completes it for you. Typing cd pro, Tab, sh, Tab becomes cd projects/shop-site/. If nothing happens, either there is no match or there are several; press Tab twice to see them.
Names with spaces
Linux allows spaces in names, but the shell uses spaces to separate arguments. A folder called College Notes must be quoted or have its space escaped with a backslash:
cd "College Notes"
cd College\ NotesBoth commands do the same thing. Without the quotes, cd College Notes would see two arguments and fail. This is one reason many Linux users name files with dashes instead, such as college-notes. Tab completion adds the backslashes for you automatically.
Advanced: a stack of directories
When you keep switching between two or three deep folders, Bash's pushd and popd act like a stack of bookmarks. pushd /etc/nginx goes there and remembers where you were; popd takes you back. dirs -v lists the stack with numbers. Most people use cd - for two places and pushd when there are more.
Common mistakes
cdinto a file.cd orders.csvfails with "Not a directory". Usecdonly on directories; open files withcatorless.- Wrong capital letters.
cd documentsfails with "No such file or directory" because the folder isDocuments. Tab completion avoids this. - Spaces without quotes.
cd My Filestries to use two arguments. Quote names with spaces. - Getting lost. When in doubt, run
pwd, or typecdalone to go home and start again.
Key points
pwdprints the current working directory as an absolute path.ls -lshows type, permissions, links, owner, group, size, date and name; add-afor hidden files and-hfor readable sizes.ls -ltsorts newest first andls -lSsorts largest first.cd dirmoves into a directory,cd ..goes up,cdalone goes home andcd -goes back.- Quote or escape names that contain spaces, and use Tab completion everywhere.
Exercise
Starting in your home folder, explore (you do not need to create anything). Go into /etc, list only the entries whose details show they are directories, go back to where you were with one command, and finally list your home folder so that the largest file appears first, with human-readable sizes.
Show solution
cd /etc
ls -l | grep '^d'
cd -
ls -lhSdrwxr-xr-x 3 root root 4096 Apr 23 09:15 apparmor drwxr-xr-x 2 root root 4096 Oct 12 06:31 apt ... /home/priya total 20K drwxrwxr-x 2 priya priya 4.0K Oct 29 18:40 Documents drwxrwxr-x 2 priya priya 4.0K Oct 27 09:12 Downloads drwxrwxr-x 2 priya priya 4.0K Oct 30 08:05 notes drwxrwxr-x 3 priya priya 4.0K Oct 28 21:30 projects -rw-rw-r-- 1 priya priya 281 Oct 30 08:15 orders.csv
grep '^d' keeps only lines that start with d, meaning directories (you will learn grep and the | pipe soon). cd - returns to the previous folder and prints it. With -S, the 4.0K directories sort above the 281-byte file.
Quick Quiz
1. Which command prints the full path of the folder you are in?
pwd prints the current working directory.
2. In drwxrwxr-x 3 priya priya 4096 Oct 28 21:30 projects, what does the first d mean?
The first character is the type: d directory, - regular file, l link.
3. Which command takes you back to the directory you were in before?
cd - switches to the previous directory; cd .. goes to the parent.
4. How do you list files with the newest first?
-t sorts by modification time, newest first; -S sorts by size.
Learn Linux with a mentor
Free lessons get you started. Our Ethical Hacking & Cyber Security training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
