Just like any other operating system, UNIX operating system keeps things tidy and ordered by storing files in a series of different directories. These directories all have standard uses, but the one we are going to pay attention to is home. Similar to the ‘My Documents’ directory on a windows system, each user has a home directory where they can store their personal files.
Home sweet home!
Having logged in using the username ‘pi’, you will first be placed into your home directory – ‘/home/pi’. We can check this by entering the pwd command (print working directory) that will display our current location.
The system will reply with a line indicating your current location in the filesystem.
We also get a clue about our location by looking at the first bit of the command prompt. The tilde (~) lets us know we are in our home directory.
pi@raspberrypi ~ $
Changing directory is achieved using the cd (change directory) command. So to change into a directory on your SD card called ‘/home/pi/files’ we can just issue the command:
We can check this has worked using pwd, or by looking at the command prompt:
pi@raspberrypi ~/files $
Alternatively we can use the tilde abbreviation for our home directory.
And again we can check our location with pwd.
Relative and absolute paths
As well as specifying the full path when referring to files or changing directories, we can use relative paths that reduce the length of command we need to execute. A single dot refers to the current directory, with a double dot referring to the parent directory.
If we first move back to our home directory using one of the following:
We can then move into the ‘files’ directory using one of the following:
To move back to our home directory we can use
Finally, showing off we can nest these commands together making something way more complex than required at the moment, but forming a useful way of thinking about moving around directories.
To move into our files directory we can issue a command which takes us home, then into the files directory referenced from that location.
To move back again we can head up two levels into the home directory, before heading down into the pi directory again:
Summary of navigation commands
||Print the working directory|
||Parent directory (one up)|