~/shio.sh/learn/pwd-ls-cd $ ./read
chapter 02 · learn the terminal
Where am I? (pwd, ls, cd)
pwd tells you where you are. ls shows what's nearby. cd moves you. The three commands you'll use a hundred times a day.
$ the filesystem, briefly
Every file on your computer lives somewhere — inside a folder, which lives inside another folder, and so on, all the way up to the root, written as /.
When you open a terminal, you start in a particular folder called your working directory. By default that's your home folder, written as ~ (a real path like /Users/you or /home/you).
Three small commands let you navigate this whole tree. That's all we need today.
$ pwd — print working directory
"Where am I?" Run pwd. The shell prints the full path of your current folder.
› try: pwd
$ ls — list what's here
"What's around me?" Run ls. It prints the names of the files and folders in your current directory. Folders are usually shown with a trailing /.
› try: ls
You can pass flags to change how ls behaves:
ls -a— also show hidden files (anything starting with.)ls -l— show a "long" listing with sizes and permissions
Flags are conventions. They start with a dash. Most commands have a few. You'll meet more as we go.
$ cd — change directory
"Take me somewhere." cd moves you into another folder. Try moving into projects:
› try: cd projects
Three magic destinations:
cd ~— home folder (or justcdalone)cd ..— up one levelcd /— the root
You can also chain: cd projects/shio goes two levels in at once.
$ the three-step
Together, pwd, ls, and cd are a kind of compass. When you feel lost — and you will, sometimes — these three will always tell you where you are and what's near you.
Next we'll read what's inside those files.
~/shio.sh/learn/pwd-ls-cd $ cd ..