When a Windows user comes into contact with the Linux world for the first time, frustration is usually not long in coming.
Especially working with the console is unfamiliar and almost impossible without knowing the right commands. The file system and folder structure is also very different compared to Windows.
To make it easier for you to get started in the Linux world, I have tried to summarize the most important information, functions and commands here.
Safety instructions
I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/
Affiliate links/advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂
Requirements
Helpful articles:
To learn how to find your way in the Linux world, it's best to get right into it. "Learning by doing" so to say. Don't be afraid to break something. The worst that could happen is that you have to reinstall Raspian.
How to do that and how to configure a working RaspberryPI in general is described in the following articles:
RaspberryPi - Setup for Nerdiys
RaspberryPI - The First Configuration
RaspberryPi – Control the RaspberryPi via SSH
Required tool:
-no-
Required material:
In the following list you will find all the parts you need to implement this article.
Commands in the console
The console under Linux is two things. On the one hand you can navigate with it through the folder structure of the RasPi's and so change the respective directory in which you are currently "located".
I (and maybe others) call this directory the working directory, because it is always the directory that is accessed by the currently executed commands.
For example, if you create a folder, it will be created in the current working directory.
Paths are also specified either starting from the working directory (relative) or absolutely from the root directory (i.e. the highest folder level).
On the other hand, the console is also a command prompt. In it, commands can be entered and executed.
Finally, it is also the commands that allow you to navigate through the folder structure.
Thereby the form of the entered commands is almost always the same.
Usually it is:
COMMAND NAME -PARAMATER PATH DETAILS
This means that a command always consists of the command name, any parameters and, if necessary, path information.
Parameters are different letters that influence the behavior of the command. These are different for each command. A complete parameter list and general help can be displayed for each command by specifying the command name and the parameter -help.
cp --help
(Note that you have to put two hyphens in front of the "help")
For example, show you all possible parameters and also a few examples of the "cp" command.
So if you ever forget how a command works or forget a parameter, you have built-in documentation at your fingertips.
Working in the console
Last entered command Display
Arrow key up/down
By pressing the up arrow key you can view your last entered command.
If you want to execute a selected one again, just press the Enter key.
If you want to edit it before, you can navigate through the command using the left and right arrow keys.
Clear terminal output
clear
This command clears the current console session and displays a "fresh" prompt.
Complete path entries
The tab key can be used to automatically complete path specifications.
For example, if you just want to change from the current folder to the next folder with the name "nextFolderWithAReallyLongName", it is enough to type the following command:
cp next
and then press the tab key.
Linux then automatically completes "next" to "nextFolderWithAnExtremelyLongName".
If the folder "naechsterOrdnerMitEinemFuerchterlichLangemNamen" is joined by a similar sounding folder (e.g. "naechsterOrdnerMitKurzemNamen") in the current directory, the folder name will only be completed as far as the two folder names differ. In this case only up to "nextFolderWith". If you then enter a letter of the desired folder, the completion can be executed again.
For example, if you enter "nextFolderWithE" and then press the Tab key, Linux already knows that the folder "nextFolderWithAFextremelyLongName" must be meant and completes the name accordingly.
So you save a lot of frimeliger typing work. This path completion works in every command.
End execution of commands
The key combination CTRL+C can be used to terminate currently running processes.
File and folder operations
Show current path
pwd
This command shows you the current absolute (i.e. complete, starting from the root directory) path to the directory you are currently in.
Show directory tree
tree
This command shows you the folder structure in the current directory.
As the name (tree) suggests, the current folder structure is displayed starting from the working directory. That is, the subfolders in folders are displayed like the branches of a tree starting from the root. This is easiest to understand by just trying it out 🙂 .
List folder contents
ls -la
This command shows you the complete content of the current directory (including hidden files). For most cases a simple command is sufficient:
ls
Create folder
mkdir newfolder
This command creates a new folder in the current directory with the specified name (in this case "newfolder").
Delete folder(including content)
rm -R newfolder
This command deletes the specified folder (in this case "newfolder") and all files contained in it without asking or warning again.
Delete file
rm file to be deleted
This command deletes the specified file (in this case the file to be deleted) in the current directory.
Change folder
cd /home/pi
This command changes the directory to the specified directory.
cd ...
Use this command to move to the next higher folder level.
This can also be linked. For example, if you want to go one folder level up from the current folder and go directly to another folder, you can do this with the following command:
cd ../newFolderInNextHoereFolder
With the following command you can go directly to your home directory:
CD ~
Copy files
cp "filename" "destination
This command copies the file “filename” to “destination”. You can also rename files directly this way.
cp coolTextfile.txt norCoolerTextfile.txt
leads for example to the fact that the "coolTexttdatei.txt" is copied again into the current folder. But the copy is then called "nochCoolereTextdatei.txt".
Path specifications can of course also be built into the copy operations.
For example, the following command copies the file "cooleTexttdatei.txt" into the subfolder "coolerUnterfolder".
cp coolTextfile.txt coolersubfolder/cooleTextfile.txt
Move multiple files or one file to another folder
mv -t destination folder file1 file2 file3
Rename file
mv currentfilename desiredfilename
This command is actually a file move (mv=move). However, since you can also specify a new name for a file move, this command is also perfect for renaming files.
Download file
wget internetAddress
This command allows to download files to the current directory.
You just have to enter the link to the file you want to download after "wget".
Unzip file with password
unzip -P PASSWORD 'zipFile.zip'
This command unpacks the password protected file "zipFile.zip" with the password "PASSWORD" into the current directory. If you want to know what zip files are, I have described this in this article:
Unzip rar file with password
unrar e -p PASSWORD 'rarFile.rar'
This command unpacks the password protected file "rarFile.zip" with the password "PASSWORD" into the current directory. If you want to know what rar files are, I have described this in this article:
Unzip file to destination folder
unzip zipFile.zip -d TARGETORDERS
This command unpacks the file "zipFile.zip" into the directory specified with ZIELORDNER.
Pack folder into zip file
zip -r filename.zip ORDNERNAME/
Secure data deletion
shred -fuz forFileAlwaysToOpen
This command not only deletes files, it also overwrites the memory area of the deleted file. As a result, the files deleted in this way cannot be recovered even by forensic means. The command works with the Gutmann method.
Installing/Working with Packages
Update program packages
sudo apt-get update && sudo apt-get upgrade
These are actually two commands linked by the "&&".
The "&&" in this case means that the first command is executed first and then the second command.
sudo apt-get update
...updates the package list of the "Advanced Packaging Tool"(apt). This tool manages different software packages. So by updating the package list, the current table of contents of the available software packages is downloaded.
sudo apt-get upgrade
...compares the packages already installed on your system with the packages available according to the table of contents. If one of the available packages is newer than the package installed on your system, it automatically installs the new version of the respective package.
Install programs/packages
sudo apt-get install PACKETNAME
This command uses the Advanced Packaging Tool to install the package specified by "PACKETNAME" and any other packages needed to run that package.
Delete unnecessary programs/packages
sudo apt-get autoremove PACKETNAME
This command is also a part of the "Advanced Packaging Tool" and can be executed with and without package name. Without package name, i.e. "sudo apt-get autoremove", this command uninstalls all packages that are no longer used because they were only installed as a prerequisite for another package that is no longer present.
Using package name, for example, "sudo apt-get autoremove IRGENDEINPAKETNAME" will uninstall the specified package and any prerequisites installed during the installation of that package.
RaspberryPi specific commands
Update firmware and kernel of the RasPi
sudo rpi update
This command updates the kernel and important system files of the RasPi. According to the motto "Never touch a running system" this should only be done when important security updates are available or something is not running as it should.
Restart RasPi
sudo reboot
This command shuts down the RasPi safely and restarts it directly. This is perfect to test if installed software starts automatically after a reboot.
Shut down RasPi safely and immediately
sudo shutdown -h -P now
or the abbreviation
sudo power off
After executing the shutdown command, you should wait a few seconds. Just as with Windows systems, it takes a moment for the system to terminate all programs/processes. This also terminates any write processes.
This is also the reason why you should always shut down the RasPi properly. If the RasPi saves a file to a memory and is then disconnected from the power, the saving process is interrupted. This then leads to the fact that possible only partially written files can no longer be read.
If this file happens to be an important file for the system, it can happen that the RasPi does not start correctly the next time.
If the RasPi is completely shut down you can see that the green LED is no longer blinking and only the red LED is on.
If you still pull the plug without shutting down the RasPi first, you don't have to burst into tears right away: Most of the time it works fine, but only most of the time 🙂 .
Run commands as root
sudo = Super User Do
This command can be placed in front of any command and causes this command to be executed as if the superUser "root" would execute it. For example, as a normal user, you can execute commands that would access files that you do not have access to as a normal user.
To be able to use sudo, you must be authorized to do so. This is defined in the file /etc/sudoers.
Log out from the console
Logout
This command terminates the connection to the RasPi and closes the console.
RasPi CPU temperature display
echo $((`cat /sys/class/thermal/thermal_zone0/temp`/1000))
This command gives you the current temperature of the CPU.
RasPi GPU temperature display
/opt/vc/bin/vcgencmd measure_temp|cut -c6-9
This command gives you the current temperature of the GPU.
Network
Display IP address or network configuration
ifconfig
This command shows you information about your network connection. You can also check which IP address your Rasp Pi has.
List open ports and existing network connections
netstat --tcp --listening --programs --numeric
This command shows you all currently open ports and network connections as well as various information about them
Other
Change password of a user
passwd userName
This command allows you to change the password of the user specified as "userName". It can also be used to set various change and lock intervals.
Show free space
df -h
This command shows you how much space is still available on your disks.
List all installed USB devices
lsusb
This command will show you all currently installed USB devices.
Show all partitions
sudo blkid
This command will show you all currently installed partitions.
Show detailed information
sudo fdisk -l
With this command you can display detailed information about your partitions.
Force file system check
sudo shutdown -rF now
The file system of the RasPI is normally only checked after every 30th reboot. With this command you force an immediate check and (if necessary) repair of the file system.
Show Serialby ID
ls -l /dev/serial/by-id
This command shows you the ID's of any USB serial adapters. So you can access serial ports directly via the ID of the USB device instead of e.g. /dev/ttyUSB0.
This has the advantage that the access via the ID is always unique and the ID does not change even after a reboot of the RasPi. If you only access a USB-serial adapter via /dev/ttyUSB0, it can happen that it is no longer accessible under /dev/ttyUSB0 but maybe under /dev/ttyUSB1 after a reboot.
To avoid this problem it is recommended to address the serial interface via the ID of the USB-serial adapter.
Show all serial interfaces
ls /dev/tty* or dmesg | grep tty
This command shows you all possible serial ports of the system.
Check other computers for presence on the network
ping network address
The "ping" command can be used to check the presence of other network users.
This can be a computer in the local network but also on the Internet.
Replace "networkAddress" with the IP address or domain name of the computer whose presence you want to check.
Show running processes
ps
The command "ps" shows you all currently running processes including the ID and some other information like load, etc.
Termination of a process identified by the process ID
kill processId
This command terminates the process with the process ID "processID".
Output of the processor load
Top
This command shows you the current load of the CPU.
Specification of the runtime and utilization of the computer
up time
With "uptime" you can see the amount of time that has passed since the RasPI was started.
Show current user
wer bin ich
This command shows you the name of the currently logged in user.
Show location of a program
which ls
This command displays the location of the program specified as prameter (in this case) "ls".
Folder structure - Which folder contains which files?
Under Linux, the folder structure is somewhat different than in Windows, but still logical. If you break down the abbreviations, the rest is almost self-explanatory.
"bin"=binaries: Executable files so programs
"sbin"=system binaries: Executable system files i.e. system programs
However, these two folders contain only files important for the pure system.
Programs installed by the user are displayed in "/usr/bin" and "/usr/sbin".
The files in these folders may also be executed by normal users.
The in "am" and "sbin" on the other hand, mostly only by users with administrator rights.
"boot": contains important files for the boot process.
"dev"=devices: This folder contains all device files. Various hardware interfaces can be addressed via these. For example USB and serial interfaces.
"lib"=libraries: Contains important libraries that are necessary for some programs.
"lost+found: If files or file fragments are found during the repair of a data medium, they are moved or saved in this folder.
"mnt"=mount: Contains all temporarily mounted volumes such as USB sticks.
"opt"=optional: Contains all manually installed programs that require their own libraries.
"proc"=processes: Contains interfaces to the loaded kernel and its procedures.
"root"=root: This is the user directory of the super user root. It is the only user directory that is not in the home directory.
"home"This is the default user folder in which each user is automatically provided with a subfolder. User files can then be stored in this folder. In the respective own user folder each user may create files or folders as desired.
"etc"=et cetera: Default location for system-wide configuration files.
Examples and explanations
Very practical I find the page tldr.ostera.io
Here you can enter the command you want to use in a search mask and further explanations and examples will be displayed automatically.
I hope this information will help you to get started in the Linux/RaspberryPI world. If not or if you have any other criticism or questions please let me know. You can simply use the comment function below the article 🙂 .
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂