If you have been using Windows or MacOS, you are familiar with the concept of files and folders. The Linux system is organised in a similar fashion: folders (directories) contain files and other folders.
The root directory /
is the first or top-most directory in the hierarchy. It can be likened to the trunk of a tree, as the starting point where all branches originate from.
Navigate folders
Use cd command to change directory. Parent directories contain child directories. .
is a shortcut for your current directory. ..
is a shortcut for the parent directory. ~
is a shortcut for your home directory (in our case /home/pi)
. Your home directory is the dedicated folder for you to keep all your files.
Use ls command to list the content of a directory.
Let's start from your home directory, then go to the root directory and list the files and folders there.
pi@raspberrypi:~ $ pwd
/home/pi
pi@raspberrypi:~ $ cd /
pi@raspberrypi:/ $ pwd
/
pi@raspberrypi:/ $ ls
bin boot debootstrap dev etc home lib lost+found media mnt
opt proc root run sbin srv sys tmp usr var
pi@raspberrypi:/ $
Now let's go back to our home directory and list files and folders there.
pi@raspberrypi:/ $ cd ~
pi@raspberrypi:~ $ pwd
/home/pi
pi@raspberrypi:~ $ ls -l
total 56
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Desktop
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Documents
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Downloads
drwxr-xr-x 8 pi pi 4096 Aug 7 18:03 liv
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 MagPi
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Music
drwxr-xr-x 3 root pi 4096 Aug 7 03:45 Network Trash Folder
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Pictures
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Public
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 python_games
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Templates
drwxr-xr-x 3 root pi 4096 Aug 7 03:45 Temporary Items
drwxr-xr-x 3 pi pi 4096 Aug 7 03:45 Videos
pi@raspberrypi:~ $
Option -l for ls command provides more details. The letter d in the first column indicates a folder. The succession of 9 letters shows read, write and execute permissions for owner, group and other users (more about that later). You can also see the name of the owner and group, size and creation date.
Let's go to /home/pi/liv
directory now and have a look at it.
$ cd liv
pi@raspberrypi:~/liv $ ls -l
total 24
drwxr-xr-x 9 pi pi 4096 Aug 7 04:24 iotConnectors
-rw-r--r-- 1 pi pi 1111 Aug 7 04:24 license
drwxr-xr-x 4 pi pi 4096 Aug 7 04:24 livAPIs
drwxr-xr-x 4 pi pi 4096 Aug 31 23:23 livDB
drwxr-xr-x 2 pi pi 4096 Aug 7 04:48 livLCD
drwxr-xr-x 2 pi pi 4096 Aug 7 20:24 livXMPP
This is the folder where all LiV Pi files are. There are 5 directories and one file in this folder. Looking into livDB, we can see a number of Python files, log files and some other directories.
pi@raspberrypi:~/liv $ ls -l livDB/
total 176
drwxr-xr-x 7 pi pi 4096 Aug 7 04:54 Adafruit_Python_BMP
drwxr-xr-x 10 pi pi 4096 Aug 7 04:41 Adafruit_Python_DHT
-rw-r--r-- 1 pi pi 985 Aug 7 04:24 airPressureSensor.py
-rw-r--r-- 1 root root 1567 Aug 7 05:08 airPressureSensor.pyc
-rwxr-xr-x 1 pi pi 1349 Aug 7 04:24 cleanLiVDB
-rw-r--r-- 1 pi pi 551 Aug 7 04:24 co2Sensor.py
-rw-r--r-- 1 root root 1080 Aug 7 05:08 co2Sensor.pyc
-rwxr-xr-x 1 pi pi 262 Aug 7 04:24 database.sql
-rw-r--r-- 1 pi pi 102400 Sep 3 22:17 liv.db
-rw-r--r-- 1 pi pi 380 Aug 7 05:10 livDB.config
-rw-r--r-- 1 pi pi 5136 Sep 3 22:17 livDB.log
-rwxr-xr-x 1 pi pi 4994 Aug 7 04:24 livDB.py
-rw-r--r-- 1 pi pi 404 Aug 7 04:24 logging.ini
-rwxr-xr-x 1 pi pi 182 Aug 7 04:24 schema.sql
-rw-r--r-- 1 pi pi 2019 Aug 7 04:38 temperatureHumiditySensor.py
-rw-r--r-- 1 root root 2246 Aug 7 05:08 temperatureHumiditySensor.pyc
-rwxr-xr-x 1 pi pi 215 Aug 7 04:24 timer.sh
pi@raspberrypi:~/liv $
Option -a lets us see "hidden" files (files whose names starts with a .
For instance, .bashrc
is a configuration file for the Bash shell. You can see it, listed alongside other hidden files in your home directory.
pi@raspberrypi:~/liv $ ls -a ..
. .dbus Music .themes
.. Desktop .nano Videos
.AppleDB Documents Network Trash Folder .vnc
.AppleDesktop Downloads Pictures work
.AppleDouble .DS_Store .profile .Xauthority
.bash_history .gnupg Public .xsession-errors
.bash_logout .gvfs python_games .xsession-errors.old
.bashrc liv .sqlite_history
.cache .local Templates
.config MagPi Temporary Items
pi@raspberrypi:~ $
Create folders and files
Now let's go up one level back to our home directory.
pi@raspberrypi:~/liv $ pwd
/home/pi/liv
pi@raspberrypi:~/liv $ cd ..
pi@raspberrypi:~ $ pwd
/home/pi
You can create a new directory with mkdir. We are going to create a new directory called work.
pi@raspberrypi:~ $ mkdir work
pi@raspberrypi:~ $ cd work
pi@raspberrypi:~/work $ pwd
/home/pi/work
Let's create a new empty file with touch.
pi@raspberrypi:~/work $ touch myfile
pi@raspberrypi:~/work $ ls -l
total 0
-rw-r--r-- 1 pi pi 0 Sep 1 00:28 myfile
pi@raspberrypi:~/work $
A file can be removed with rm.
pi@raspberrypi:~/work $ ls -l
total 0
-rw-r--r-- 1 pi pi 0 Sep 1 00:28 myfile
pi@raspberrypi:~/work $ rm myfile
pi@raspberrypi:~/work $ ls -l
total 0
pi@raspberrypi:~/work $