General tips on Linux
Change python version
In order to change from default python 2.7 to python 3, use the following command : update-alternatives --install /usr/bin/python python /usr/bin/python3 10
fabgt@fabgt-SAT:~$ python
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
fabgt@fabgt-SAT:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode
fabgt@fabgt-SAT:~$ python
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
File Permissions
Basics
We can use the -l (long format) option to have ls list the file permissions for files and directories.
fabgt@fabgt-SAT:~/gitclone/HoneywellPMS$ ls -l
total 24
-rw-rw-r-- 1 fabgt fabgt 529 jan 9 00:00 ESP8266MOD_12S.py
-rw-rw-r-- 1 fabgt fabgt 2172 jan 8 23:54 ESP8266.py
-rwxrwxrwx 1 root root 321 jan 9 14:05 gui_app.py
-rw-rw-r-- 1 fabgt fabgt 3256 dec 18 17:46 main.py
-rw-rw-r-- 1 fabgt fabgt 3319 dec 18 18:28 MeasurementPMSHoneywell.py
-rw-rw-r-- 1 fabgt fabgt 1613 jan 5 17:22 wifi.py
On each line, the first character identifies the type of entry that is being listed. If it is a dash (-) it is a file. If it is the letter d it is a directory.
The next nine characters represent the settings for the three sets of permissions.
The first three characters show the permissions for the user who owns the file (user permissions). The middle three characters show the permissions for members of the file’s group (group permissions). The last three characters show the permissions for anyone not in the first two categories (other permissions).
There are three characters in each set of permissions. The characters are indicators for the presence or absence of one of the permissions. They are either a dash (-) or a letter. If the character is a dash, it means that permission is not granted. If the character is an r, w, or an x, that permission has been granted.
The letters represent:
r: Read permissions. The file can be opened, and its content viewed.
w: Write permissions. The file can be edited, modified, and deleted.
x: Execute permissions. If the file is a script or a program, it can be run (executed).
For example:
— means no permissions have been granted at all. rwx means full permissions have been granted. The read, write, and execute indicators are all present.
Permissions Syntax
To use chmod to set permissions, we need to tell it:
Who: Who we are setting permissions for. What: What change are we making? Are we adding or removing the permission? Which: Which of the permissions are we setting?
We use indicators to represent these values, and form short “permissions statements” such as u+x, where “u” means ” user” (who), “+” means add (what), and “x” means the execute permission (which).
The “who” values we can use are:
u: User, meaning the owner of the file. g: Group, meaning members of the group the file belongs to. o: Others, meaning people not governed by the u and g permissions. a: All, meaning all of the above.
If none of these are used, chmod behaves as if “a” had been used.
The “what” values we can use are:
–: Minus sign. Removes the permission. +: Plus sign. Grants the permission. The permission is added to the existing permissions. If you want to have this permission and only this permission set, use the = option, described below. =: Equals sign. Set a permission and remove others.
The “which ” values we can use are:
r: The read permission. w: The write permission. x: The execute permission.
Setting and modifying Permissions
fabgt@fabgt-SAT:~/gitclone/HoneywellPMS$ ls -l new_file.txt
-rw-rw-r-- 1 fabgt fabgt 6 jan 9 14:20 new_file.txt
We want the group and other users to have read permissions only. We can do using the following command:
chmod og=r new_file.txt
fabgt@fabgt-SAT:~/gitclone/HoneywellPMS$ ls -l new_file.txt
-rw-r--r-- 1 fabgt fabgt 6 jan 9 14:20 new_file.txt
We can add the execute permission for everyone with the following command:
chmod a+x new_file.txt or chmod +x new_file.txt
fabgt@fabgt-SAT:~/gitclone/HoneywellPMS$ sudo chmod a+x new_file.txt
fabgt@fabgt-SAT:~/gitclone/HoneywellPMS$ ls -l
-rwxr-xr-x 1 fabgt fabgt 6 jan 9 14:20 new_file.txt
Ports
List usb interface ports
Using ´´sudo lsusb´´ :