ShareYourGroupShareYourGroupCommands

Linux and Mac commands

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?

Linux or Mac terminal
asha@pc:~/demo$ pwd
/home/asha/demo

pwd stands for print working directory. Get into the habit of running it before any command that deletes or overwrites.

Moving

Linux or Mac terminal
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/demo

Two 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.

PathMeaning
/the root: the top of the whole system
/home/ashaan absolute path, starting from the root
photosa relative path, starting from where you are
.this folder
..the folder above
../oldup one, then into old
~your home folder
~/DocumentsDocuments inside your home folder

On Linux, home folders live in /home. On a Mac they live in /Users.

Shortcuts for cd

CommandGoes to
cdyour 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".

Linux or Mac terminal not run here
cd Photos
What the output looks like an illustration, not a real run
bash: cd: Photos: No such file or directory

The 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

Linux or Mac terminal
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.

Linux or Mac terminal
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.

Linux or Mac terminal
asha@pc:~/demo$ mkdir empty
asha@pc:~/demo$ rmdir empty
asha@pc:~/demo$ rmdir photos
rmdir: failed to remove 'photos': Directory not empty

The 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.

Linux or Mac terminal
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/demo

Many 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.

Linux or Mac terminal
asha@pc:~/demo$ find . -type d
.
./old
./photos
./reports
./reports/2026
./reports/2026/november
./tax papers

Opening the folder in a window

Going the other way on a Mac, dragging a folder from Finder onto the Terminal window types its path for you.

Common mistakes

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.