Figure 2-3. LXTerminal gives you access to the command line
(or shell).
Files and the Filesystem
Table 2-1 shows some of the important directories in the filesys-
tem. Most of these follow the Linux standard of where files should
go; a couple are specific to the Raspberry Pi. The
/sys
directory is
where you can access all of the hardware on the Raspberry Pi.
Table 2-1. Important directories in the Raspberry Pi OS
file system
34 Getting Started with Raspberry Pi
GSW_RASPI_4ED_FIN.indd 34GSW_RASPI_4ED_FIN.indd 34 10/28/21 10:53 AM10/28/21 10:53 AM
Directory
Description
/bin
Programs and commands that all users can run
/boot
All the files needed at boot time
/dev
Special files that represent the devices
on your system
/etc
Configuration files
/etc/init.d
Scripts to start up services
/etc/X11
X11 configuration files
/home
User home directories
/home/pi
Home directory for Pi user
/lib
Kernel modules/drivers
/media
Mount points for removable media
/proc
Virtual directory with details about run-
ning processes and the OS
/sbin
Programs for system maintenance
/sys
A special directory on the Raspberry Pi
that represents the hardware devices
/tmp
Space for programs to create temporary files
/usr
Programs and data usable by all users
/usr/bin
Most of the programs in the operating system
reside here
/usr/games
Games (surprise!) No, it’s empty by default
/usr/lib
Libraries to support common programs
/usr/local
Software that may be specific to this machine
goes here
/usr/sbin
More system administration programs
/usr/share
Supporting files that aren’t specific to any process
or architecture
/usr/src
Linux is open-source; here’s the source!
/var
System logs and spool files
/var/
backups
Backup copies of all the most vital system files
/var/cache
Programs such as apt-get cache their data here
/var/log
All of the system logs and individual service logs
/var/mail
All user email is stored here, if you’re setup
to handle email
/var/spool
Data waiting to be processed (e.g., incoming
email, print jobs)
GSW_RASPI_4ED_FIN.indd 35GSW_RASPI_4ED_FIN.indd 35 10/28/21 10:53 AM10/28/21 10:53 AM
You’ll see your current directory displayed before the command
prompt. In Linux, your home directory has a shorthand notation:
the tilde (~). When you open the LXTerminal, you’ll be dropped into
your home directory, and your prompt will look like this:
pi@raspberrypi:~ $
Here’s an explanation of that prompt:
pi@
raspberrypi: ~ $
Your username, pi, followed by the at (@) symbol.
The name of your computer (raspberry pi is the default host
name). It can be changed.
The
current working directory
of the shell. You always start
in your home directory (~). If you should change directo-
ries into the Documents directory, the prompt will change to
pi@raspberrypi:~/Documents $
This is the
shell prompt
. Any text you type will appear to the right
of it. Press Enter or Return to execute each command you type.
Later in the book, we will omit the pi@raspberrypi ~
portion of the prompt and just show you the $ in some
examples, to keep things less cluttered.
Use the cd (change directory) command to move around the file
system. The following two commands have the same effect (chang-
ing to the home directory) for the Pi user:
cd /home/pi/
cd ~
In addition, if you just type cd, you’ll be taken to the home directory.
It’s a handy shortcut to know.
If the directory path starts with a forward slash, it will be interpreted
as an absolute path to the directory. Otherwise, the directory will be
considered relative to the current working directory. You can also use
. and .. to refer to the current directory and the current directory’s
parent. For example, to move up to the top of the filesystem:
36 Getting Started with Raspberry Pi
GSW_RASPI_4ED_FIN.indd 36GSW_RASPI_4ED_FIN.indd 36 10/28/21 10:53 AM10/28/21 10:53 AM
pi@raspberrypi:~ $ cd..
pi@raspberrypi:/home $ cd..
You could also get there with the absolute path/ :
pi@raspberrypi:~ $ cd /
Once you’ve changed to a directory, use the ls command to list the
files there:
pi@raspberrypi:/ $ ls
bin dev home lost+found mnt proc run selinux sys usr
boot etc lib media opt root sbin srv tmp var
Most commands have additional parameters, or
switches
, that can
be used to turn on different behaviors. For example, the -l switch
will produce a more detailed listing, showing file sizes, dates, and
permissions:
pi@raspberrypi:~ $ ls -l
total 8
drwxr-xr-x2pipi4096Oct1214:26Desktop
drwxrwxr-x2pipi4096Jul2014:07python_games
The -a switch will list all files, including invisible ones (invisible file
names begin with a dot):
pi@raspberrypi:~ $ ls -la
total 80
drwxr-xr-x 11 pi pi 4096 Oct 12 14:26
.
drwxr-xr-x 3 root root 4096 Sep 18 07:48 ..
-rw-------
1 pi pi 25 Sep 18 09:22 .bash_history
-rw-r--r--
1 pi pi 220 Sep 18 07:48 .bash_logout
-rw-r--r--
1 pi pi 3243 Sep 18 07:48 .bashrc
drwxr-xr-x
6 pi pi 4096 Sep 19 01:19 .cache
drwxr-xr-x
9 pi pi 4096 Oct 12 12:57 .cong
drwx------
3 pi pi 4096 Sep 18 09:24 .dbus
drwxr-xr-x
2 pi pi 4096 Oct 12 14:26 Desktop
-rw-r--r--
1 pi pi 36 Sep 18 09:35 .dmrc
drwx------
2 pi pi 4096 Sep 18 09:24 .gvfs
drwxr-xr-x
2 pi pi 4096 Oct 12 12:53 .idlerc
-rw-------
1 pi pi 35 Sep 18 12:11 .lesshst
drwx------
3 pi pi 4096 Sep 19 01:19 .local
-rw-r--r--
1 pi pi 675 Sep 18 07:48 .prole
drwxrwxr-x
2 pi pi 4096 Jul 20 14:07 python_games
drwx------
4 pi pi 4096 Oct 12 12:57 .thumbnails
-rw-------
1 pi pi 56 Sep 18 09:35 .Xauthority
-rw-------
1 pi pi 300 Oct 12 12:57 .xsession-errors
-rw-------
1 pi pi 1391 Sep 18 09:35 .xsession-errors.old
Getting Around Linux on the Raspberry Pi 37
GSW_RASPI_4ED_FIN.indd 37GSW_RASPI_4ED_FIN.indd 37 10/28/21 10:53 AM10/28/21 10:53 AM
drwxr-xr-x 11 pi pi 4096 Oct 12 14:26 .
drwxr-xr-x 3 root root 4096 Sep 18 07:48 ..
-rw------- 1 pi pi 25 Sep 18 09:22 .bash_history
-rw-r--r-- 1 pi pi 220 Sep 18 07:48 .bash_logout
-rw-r--r-- 1 pi pi 3243 Sep 18 07:48 .bashrc
drwxr-xr-x 6 pi pi 4096 Sep 19 01:19 .cache
drwxr-xr-x 9 pi pi 4096 Oct 12 12:57 .cong
drwx------ 3 pi pi 4096 Sep 18 09:24 .dbus
drwxr-xr-x 2 pi pi 4096 Oct 12 14:26 Desktop
-rw-r--r-- 1 pi pi 36 Sep 18 09:35 .dmrc
drwx------ 2 pi pi 4096 Sep 18 09:24 .gvfs
drwxr-xr-x 2 pi pi 4096 Oct 12 12:53 .idlerc
-rw------- 1 pi pi 35 Sep 18 12:11 .lesshst
drwx------ 3 pi pi 4096 Sep 19 01:19 .local
-rw-r--r-- 1 pi pi 675 Sep 18 07:48 .prole
drwxrwxr-x 2 pi pi 4096 Jul 20 14:07 python_games
drwx------ 4 pi pi 4096 Oct 12 12:57 .thumbnails
-rw------- 1 pi pi 56 Sep 18 09:35 .Xauthority
-rw------- 1 pi pi 300 Oct 12 12:57 .xsession-errors
-rw------- 1 pi pi 1391 Sep 18 09:35 .xsession-errors.old
Use the mv command to rename a file. The touch command can be
used to create an empty dummy file:
pi@raspberrypi:~ $ touch foo
pi@raspberrypi:~ $ ls
foo Desktop python_games
pi@raspberrypi:~ $ mv foo baz
pi@raspberrypi:~ $ ls
baz Desktop python_games
Remove a file with rm. To remove a directory, you can use rmdir if the
directory is empty, or rm -r if it isn’t. The -r is a parameter sent to
the rm command that indicates it should recursively delete every-
thing in the directory.
rm -r is a bit like nuclear war—it is easy to start, and it
does great damage. Make sure you’re in exactly the
right directory before you set it off.
38 Getting Started with Raspberry Pi
GSW_RASPI_4ED_FIN.indd 38GSW_RASPI_4ED_FIN.indd 38 10/28/21 10:54 AM10/28/21 10:54 AM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset