Move around the filesystem
Use cd to move between directories. For example,
type cd animals to move into the animals directory. You can jump multiple directories at once as
well:
$ cd animals/dogs
Moves to the dogs directory inside the animals directory.
If you want to go to the home directory as quickly as possible, omit the directory entirely:
$ cd
Moves to the home directory.
If you are ever lost, you can print the full path to the current
directory with pwd. It’s a handy command to
know when you are new to the terminal, but as you get more comfortable
you should find yourself using it less and less.
View the contents of the current directory with ls. If you want to view the contents of
another directory, you can do that too:
$ ls animals
Views the content of the animals directory.
The ls command has a number of useful flags:
-l lists files using a detailed format that
includes the permissions, file size, and latest modification date for each
file:
$ ls -l
-rw-rw-r-- 1 mauritz mauritz 1264 Dec 5 13:30 dogs.txt
Use ls -lh to show human-readable files sizes
like GB, MB, etc.
By default, ls does not list hidden files. To
include hidden files in the output, use the -A flag.
When you are using cd and ls, there are a few special paths that you
might want to be aware of:
.. is the parent directory. Type ../animals to go to the animals directory one level above.
~ is the home directory. Type cd ~/Downloads to move into the Downloads directory no matter where you are in the filesystem.
/ is the filesystem root. Start a path with / if you want to move somewhere irrespective
of where you are on the system. Paths starting with / are usually called absolute paths, as opposed to relative paths that are dependent on the
current directory.