Guide to use the Raspberry
After the first introductory article on Raspberry, where we started setting it up and configuring it, now I show you the main commands guide for to do an efficient work with it.
Update the raspberry system
As first step, it would be useful to update our Raspberry, so we give as a command
sudo aptitude update
sudo aptitude upgrade
or we could go to use the good old Linux commands
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
When we will analyze the command, we will have, in the first case one directive that updates the package dependency tree and one that updates the packages mentioned. After the first command, a new version is available; in the second case we will use the our dear and old apt-get which is nothing else, like aptitude, a package manager used on the vast majority of Linux distros: in this specific case like first thing we will always update the dependency tree, (update) then to update the program packages (upgrade) and finally we update the distribution (dist-upgrade). Now our Raspberry is updated and ready to use.
SUDO e CHMOD
Sudo is nothing more than the acronym of Super User DO and it is with this command, that usually we have already used, that is possible to launch programs with root administrative rights. Some modifications (installing and uninstalling packages, removing system files, changing user permissions, etc.) they can be carried out only preferring it at the main command with this keyword. Usually the “SUDO” command always asks for the password to be entered in order to allow a program to run as super user (roots rights) except with the Raspberry where a configuration parameter has been changed that allows us to launch it by omitting the password.
If instead we want to change the access permissions to a file and directory we will use the command chmod.When we invoke the command ls -l
The files are listed with their characteristics; we will get for example -rwxrwxr--
the string can be interpreted simply by excluding the first character that defines whether it is a file or a folder (d if it is a directory – if it is a file) and dividing the rest of the line into three triples that identify the permissions in order that have the creator user (owner), the permissions of the workgroup to which the owner belongs and finally the permissions that all the other users of the system have.
The values expressed are:
- r , reading permit;
- w , writing permit;
- x , execution permit.
For example, to add the permissions to the running user, just postpone one of the three values preceded by a + to the user, while to remove a –
chmod <id name>+x <file name>
chmod <id name>-xw <file name>
in the first case we will give the execution privilege and in the second case we remove this privilege including the write one.
Folder operations
As a first step we will learn how to create or delete folders. With command
mkdir <folder name>
we’re going to create it and with the command
rmdir <folder name>
we are going to eliminate it; but be careful! When we use the latter because it only works on empty folders, if there is even a hidden file inside, the system will refuse to proceed.
To be able to read the contents of a directory we will use the command ls (list) which can be launched with or without options. Commonly the most used are:
- -l file details;
- -a show all files even hidden ones;
- -h file sizes.
To be able to move within the folder tree, the command comes to our aid is cd (change directory);if we want to access a folder in the current one, just type
cd <folder name>
(be careful not to insert “/” before the folder name otherwise it will be searched in the system root); if, on the other hand, we want to go back to one the directory branch, just type
cd ..
Type the keyword “cd” to simply return to the initial home folder instead.
File operations
To create an empty file we simply type
touch <file name>
To move or rename a file instead we just need to use mv
mv <file name> <new file name>
for to change the name
mv <file name> <folder name>/<file name>
to move it.
To copy files and directories, we will invoke the cp command which works pretty much like mv but has a particular option (-r) which allows us to copy the files present in the subfolders as well
cp -r document/* backup/
In this way the backup is simplified. We just have to learn how to delete a file, nothing more trivial
rm <file name>
and “the game is done”.
For all the commands we can select all the files that contain, or end with the same word, using combinations of text and the special asterisk character *. Here are some examples:
mv script.* archivio/
move all files named scripts to the archive subfolder
rm *script*
deletes all files in the current folder that contain the word script
cp * archivio/
copies all files in the current folder to the archive folder.
This article is just an exhaustive guide to the commands that can be launched from the terminal via the command line. If you are a beginner, it is good to know that most programs are accompanied by a user manual that can be consulted by launching the command
man <comand>
or provide a quick guide that can be consulted via
<comand> --help
moreover on the net it is possible to find with a simple search everything we need. For a simpler use of the terminal, remember that the commands already launched in execution are kept in memory and we can scroll through them using the up and down directional arrows. If, on the other hand, we want to interrupt a program launched by mistake, use the key combination ctrl + c.
Finally, to turn off our Raspberry, we run the command
sudo poweroff
o
sudo shutdown
to restart it
sudo reboot
o in case we just want to close our ssh connection without turning off the raspberry just type
logout