pwd, ls and cd — Finding Your Way
You open a terminal and see only a blinking cursor. There are no windows or icons, so you can't glance at a desktop to see where you are. On the command line you ask, and three tiny commands do most of the asking. Throughout this course we'll follow Asha, who keeps her community garden's records in a folder called garden in her home directory.
The rule
Where am I, what is here, go there: pwd, ls, cd.
pwd (print working directory) tells you which folder the shell is "standing in" right now:
$ pwd
/home/ashals (list) shows what is inside the current folder, or inside any folder you name:
$ ls
garden photos todo.txt
$ ls garden
harvest.csv notes.txt plotsTwo options you'll use every day:
ls -lgives the long listing, with permissions, owner, size and date on each line.ls -ashows all entries, including hidden ones whose names start with a dot, such as.bashrc.
You can combine them: ls -la.
cd (change directory) moves you:
$ cd garden
$ pwd
/home/asha/gardenA path is written one of two ways:
- Absolute paths start with
/and describe the full route from the top of the system:/home/asha/garden. - Relative paths start from where you are now:
garden, orplots.
A few special names work anywhere:
| Name | Means |
|---|---|
. |
this directory |
.. |
the parent directory, one level up |
~ |
your home directory |
- |
(with cd) the directory you were in before |
A plain cd with nothing after it takes you home.