cd, pwd, mkdir and rmdir: move around and make folders
The terminal is always "in" one folder, called the working directory. Commands act there unless you give another path. pwd tells you where you are, cd takes you somewhere else, and mkdir makes new folders.
Where am I?
asha@pc:~/demo$ pwd
/home/asha/demopwd stands for print working directory. Get into the habit of running it before any command that deletes or overwrites.
Moving
asha@pc:~/demo$ cd photos
asha@pc:~/demo/photos$ pwd
/home/asha/demo/photos
asha@pc:~/demo/photos$ cd ..
asha@pc:~/demo$ pwd
/home/asha/demoTwo dots mean the folder above.
Paths
A path is a route to a file or folder. Linux and the Mac separate its parts with a forward slash.
| Path | Meaning |
|---|---|
/ | the root: the top of the whole system |
/home/asha | an absolute path, starting from the root |
photos | a relative path, starting from where you are |
. | this folder |
.. | the folder above |
../old | up one, then into old |
~ | your home folder |
~/Documents | Documents inside your home folder |
On Linux, home folders live in /home. On a Mac they live in /Users.
Shortcuts for cd
| Command | Goes to |
|---|---|
cd | your home folder |
cd ~ | your home folder |
cd - | the folder you were in before this one |
cd / | the root |
cd ../.. | two levels up |
cd - is worth remembering. It flips between two folders, however far apart.
Capital letters matter
On Linux, Photos and photos are two different names. Typing the wrong case gives "No such file or directory".
cd Photosbash: cd: Photos: No such file or directoryThe Mac's usual file system ignores case here, but scripts written on a Mac then fail on Linux, so type names exactly.
Press Tab after the first few letters and the shell completes the name, with the right case.
Making folders
asha@pc:~/demo$ mkdir reports
asha@pc:~/demo$ ls -F
log.txt
marks.csv
notes.txt
old/
photos/
report.txt
reports/To make a folder inside a folder that does not exist yet, add -p. It creates every missing level and does not complain if the folder is already there.
asha@pc:~/demo$ mkdir reports/2026/november
mkdir: cannot create directory 'reports/2026/november': No such file or directory
asha@pc:~/demo$ mkdir -p reports/2026/november
asha@pc:~/demo$ ls -R reports
reports:
2026
reports/2026:
november
reports/2026/november:The first command failed because reports/2026 did not exist. With -p it worked.
Several folders can be made at once: mkdir jan feb mar.
Removing folders
rmdir removes a folder only if it is empty.
asha@pc:~/demo$ mkdir empty
asha@pc:~/demo$ rmdir empty
asha@pc:~/demo$ rmdir photos
rmdir: failed to remove 'photos': Directory not emptyThe refusal for photos is a protection. To remove a folder that has things in it, the command is rm -r, which is powerful and dangerous. It has a page of its own.
Names with spaces
A space separates arguments, so a name containing one must be quoted or escaped.
asha@pc:~/demo$ mkdir "tax papers"
asha@pc:~/demo$ ls -F
log.txt
marks.csv
notes.txt
old/
photos/
report.txt
reports/
tax papers/
asha@pc:~/demo$ cd "tax papers"
asha@pc:~/demo$ pwd
/home/asha/demoMany people avoid the problem by using dashes or underscores in names: tax-papers.
Seeing the structure
ls -R lists everything below. A clearer picture comes from the tree command, which is not installed by default on every system. find . -type d lists every folder below the current one, and works everywhere.
asha@pc:~/demo$ find . -type d
.
./old
./photos
./reports
./reports/2026
./reports/2026/november
./tax papersOpening the folder in a window
- On a Mac:
open . - On most Linux desktops:
xdg-open .
Going the other way on a Mac, dragging a folder from Finder onto the Terminal window types its path for you.
Common mistakes
- "No such file or directory." Misspelling, wrong case, or the folder is not where you think. Run
ls. - "Not a directory." You tried to
cdinto a file. - "Permission denied." The folder belongs to someone else or to the system.
- Forgetting where you are. Run
pwd.
The Windows equivalents are cd, mkdir and rmdir.
Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.
This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.