The next part in our Terminal series is Navigation. Last time we viewed the data and learnt how to List the data in various different ways. Now we are going to learn how to Navigate between Directories
Changing Directories
When you first log in, your location is /home/pi
, we found out where we are using the pwd
command. Lets first do a Long List to see what we have
[email protected] ~ $ ls -l total 44 drwxr-xr-x 2 pi pi 4096 Sep 17 08:50 Desktop drwxr-xr-x 3 pi pi 4096 Aug 1 19:48 Documents drwx------ 2 pi pi 4096 Sep 6 20:01 Downloads drwxr-xr-x 3 pi pi 4096 Aug 9 19:50 indiecity -rw-r--r-- 1 pi pi 2153 Jun 29 09:41 npm-debug.log -rw-r--r-- 1 pi pi 5781 Feb 3 2013 ocr_pi.png drwxr-xr-x 2 pi pi 4096 Aug 9 08:41 python drwxrwxr-x 2 pi pi 4096 Jan 1 1970 python_games drwxr-xr-x 2 pi pi 4096 Aug 1 19:48 Scratch drwxr-xr-x 3 pi pi 4096 Jun 28 15:41 wwwroot
The first column of the list, details what the data type is and permission levels
drwxr-xr-x
The d
tells us that it is a Directory, if there is a -
this means it is just a file
rwxr-xr-x
This is the permissions for the Owner, Group and Others, no need to worry about this right now
So we want to Change Directory into the Documents Directory
[email protected] ~ $ cd Documents/ [email protected] ~/Documents $
So cd stands for Change Directory, then you type out the name of the directory that you want to change into. UNIX/Linux is type sensitive:- so Documents and documents are 2 different things. One thing that you can use is Tab Completion. So what you can do is type cd Doc
and press the TAB
key and it auto completes it for you. The File/Directory has to have a unique name though.
If I typed cd D
, it would list me all of the Files/Directories that start with the letter D
[email protected] ~ $ cd D Desktop/ Documents/ Downloads/
When you hange into a directory, you will notice that the command prompt changes to show your new directory
[email protected] ~/Documents $
Then just do a quick ls -t
to see what is inside of the Directory
[email protected] ~/Documents $ ls -l total 4 drwxr-xr-x 2 pi pi 4096 Aug 1 19:48 Scratch Projects
So that was navigating into a directory, there are a few things we can input after the cd
command
Command | Description |
---|---|
.. | Navigates up one directory |
~ | The tilde navigates you to your home directory |
/ | Forward slash is the root directory, the highest directory |
So to navigate up one level we do the following
[email protected] ~/Documents $ cd .. [email protected] ~ $
Notice that the prompt looses the word Documents
as we have moved back up to our home directory.
So if you wanted to navigate to your Documents directory from anywhere on you Pi, you would type
[email protected] ~ $ cd ~/Documents/ [email protected] ~/Documents $
This changes to the ~
home of the current user, then into the Documents
directory
So that is how easy it is to navigate in and out of Directories.