Introduction
Raspberry Pi commands allow us to work on a wide range of applications. Raspberry Pi can provide support from building a prototype to developing an existing software.
In this post, you will learn 5 really useful command line tools to use your Raspberry Pi or Raspberry PLC in a safe environment.
Related links
Let's see the most basic and commonly used Raspberry Pi Commands
Vcgencmd measure_temp
Vcgencmd is a command line utility that can get various pieces of information from the VideoCore GPU on the Raspberry Pi.
It is important to know the Raspberry temperature because excessive heat can lead you to unwanted situations. In fact, those who overclocked the processor of the Raspberry, must check the temperature frequently, because all the Raspberry Pi models perform a degree of thermal management to avoid overheating under heavy load. The SoCs have an internal temperature sensor, which software on the GPU polls to ensure that temperatures do not exceed a predefined limit.Â
When the core temperature is between 80ºC and 85ºC, a warning icon showing a red half-filled thermometer will be displayed, and the ARM cores will be progressively throttled back.
So, use measure_temp option, to get the temperature of the SoC (System on Chip) as measured by the on-board temperature sensor, to help you with the temperature control of your device.
Check out the next URL to know more about vcgencmd
Htop
Htop is a really powerful command line utility that allows you to interactively monitor your system's vital resources or server processes in real-time.
It is quite similar to the top command. However, since htop is a newer program compared to top, it offers many improvements.Â
Htop also supports mouse operations, uses colors in its outputs and gives visual indications about processor, memory and swap usage.Â
It also prints full command lines for processes and allows one to scroll both vertically and horizontally for processes and command lines respectively.
You can install it by doing:
sudo apt update
sudo apt install htop
So, if you run htop in the command line, you will get something like this:
Finally, if you click on F1, you will get some help with the possibilities and you will see how it works.
Dmesg
The Linux kernel is the core of the operating system that controls access to the system resources, such as CPU, I/O devices, physical memory, and file systems. The kernel writes several messages to the kernel ring buffer during the boot process and when the system is running.Â
The kernel ring buffer is a portion of the physical memory that holds the kernel's log messages. It has a fixed size, which means that once the buffer is full, the older logs records are overwritten.
Dmesg is used to examine or control the kernel ring buffer. It is really useful for examining kernel boot messages and debugging hardware related issues. The default action is to display all messages from the kernel ring buffer.
So, just execute it like:
dmesg
Usage
dmesg [options]
If you see that the dmesg command shows too many messages that you are not able to read, then find the words you really want to find using | grep:
dmesg | grep eth0
To know more about this command and its options, just type:
dmesg -h
or
man dmesg
Comma and braces operators
We can do a lot with comma and braces operations, to make our life easier, let's see a few usages:
- Rename and backup operations with comma & braces operators
- Pattern matching with comma & braces operator
- Rename and backup (prefixing name) operations on long file names
- To copy files from a parent directory without typing two times the long path
1. To back up hello.txt to hello.txt.bak:
cp hello.txt{,.bak,}
2. To revert the file from hello.txt.bak to hello.txt:
mv hello.txt{.bak,}
3. To rename the file with prefix "1-":
cp hello.txt 1-!#^
4. To copy files from a parent directory without typing two times the long path.
cp firstDir/secondDir/thirdDir/{hello.txt,bye.txt}
Control + R
Can you imagine that you could autocomplete your commands with the ones that you typed before? Something like Google Autocomplete. Would be really useful, right? That is possible by opening up a terminal windows and just trying the following:
1. Ctrl + R
2. Start typing your command and some suggestion will appear:
3. If you want to type the suggested command, then click on the Tab or the right arrow of your keyboard, and that suggested command will be set on your command line ready to use. In case you want to see more suggested commands, then try Ctrl + R again until you see the command you want to execute.
Finally, some tricky commands
1. Type "rev" to reverse the message to type:
rev
2. Type "factor <number>" to factor any number:
3. Finally, just type the following, and see what happens:
apt moo
apt-get --help | grep -i cow
Most Useful Commands for Raspberry Pi automation