Raspberry Pi : Useful commands

Raspberry Pi is a computer that works under Linux. Although many things can be done using software which have a graphic interface, the command Terminal remains omnipresent to configure, update, install. Sick looking for orders on the internet, I ended up writing a little article that focuses a lot of things on a daily basis when we work fun with a Raspberry

How to recover the characteristics of the Raspberry Pi

cat command to recover many features of the Raspberry Pi. Here’s what you can find out about your Raspberry:

  • cat/proc/cpuinfo : the microprocessor, model features, frequency, version number, number of cores…
  • / proc/meminfo cat : displays information about the memory of the Raspberry Pi (total, free memory…)
  • cat/proc/partitions : to know the size of the partitions (including the size of the SD card)
  • cat/proc/version : version of linux installed

linux raspberry commande cat proc cpuinfo

List the connected USB devices

If you do a bit of automation, it is sometimes necessary to know the USB port on which a device is connected. Here is a list of useful commands. For writing the article, I have connected an old DELL and a Wemos D1 Mini keyboard which used Gateway MySensors.

Let’s start simply by listing the devices USB with the command lsusb . We get all connected USB devices. In my case, we find the DELL keyboard (which can also be a USB hub) and the Wemos which is connected to the device 6. It’s interesting to see that the Ethernet adapter and itself connected by USB to the RPI.

linux raspberry commande lsusb

List of devices connected by USB (lsusb).

That’s fine but we still don’t know the port tty that the USB device is mapped. There are several solutions but the easiest I’ve found is this. First unplug your unit and then cut off the. Then run the command dmesg s 1024 . This command allows to retrieve the latest system messages. Here is what I get when I plug the Wemos on the USB port.

linux raspberry commande dmesg s 1024

If your device communicates via the serial port ( usb-serial ) with the Raspberry. This is the case for many DIY (RFXCom, Gateway MySensors, Arduino…) home automation devices, you can check with the command ls-l/sys/bus/usb-serial/devices.

pi@raspberrypi:/sys/class/tty/ttyUSB0 $ ls -l /sys/bus/usb-serial/devices
total 0
lrwxrwxrwx 1 root root 0 sep 16 07:42 ttyUSB0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0

One finds the Wemos ttyUSB0 port.

If you want to get more information, do use the command udevadm. in the example below, we get the info on the port / dev/ttyUSB0 . If no device is connected, you will have the return device node not found.

pi@raspberrypi:~ $ udevadm info -a -p  $(udevadm info -q path -n /dev/ttyUSB0)

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0':
    KERNELS=="ttyUSB0"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="ch341-uart"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0':
    KERNELS=="1-1.2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="ch341"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bInterfaceProtocol}=="02"
    ATTRS{bNumEndpoints}=="03"
    ATTRS{authorized}=="1"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2':
    KERNELS=="1-1.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.2"
    ATTRS{idVendor}=="1a86"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="6"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="96mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0254"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="20"
    ATTRS{ltm_capable}=="no"
    ATTRS{removable}=="removable"
    ATTRS{idProduct}=="7523"
    ATTRS{bDeviceClass}=="ff"
    ATTRS{product}=="USB2.0-Serial"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="02"
    ATTRS{devpath}=="1"
    ATTRS{idVendor}=="0424"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="2"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="2mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="5"
    ATTRS{bcdDevice}=="0200"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="56"
    ATTRS{ltm_capable}=="no"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="9514"
    ATTRS{bDeviceClass}=="09"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{devpath}=="0"
    ATTRS{idVendor}=="1d6b"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{authorized_default}=="1"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="1"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{bcdDevice}=="0404"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="3f980000.usb"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="25"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 4.4.11-v7+ dwc_otg_hcd"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0002"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="DWC OTG Controller"

  looking at parent device '/devices/platform/soc/3f980000.usb':
    KERNELS=="3f980000.usb"
    SUBSYSTEMS=="platform"
    DRIVERS=="dwc_otg"
    ATTRS{hnp}=="HstNegScs = 0x0"
    ATTRS{srp}=="SesReqScs = 0x1"
    ATTRS{regvalue}=="invalid offset"
    ATTRS{hsic_connect}=="HSIC Connect = 0x1"
    ATTRS{guid}=="GUID = 0x2708a000"
    ATTRS{mode}=="Mode = 0x1"
    ATTRS{srpcapable}=="SRPCapable = 0x1"
    ATTRS{regdump}=="Register Dump"
    ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000"
    ATTRS{ggpio}=="GGPIO = 0x00000000"
    ATTRS{hprt0}=="HPRT0 = 0x00001005"
    ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 380 msecs (38 jiffies)"
    ATTRS{driver_override}=="(null)"
    ATTRS{hcd_frrem}=="HCD Dump Frame Remaining"
    ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0"
    ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306"
    ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0"
    ATTRS{busconnected}=="Bus Connected = 0x1"
    ATTRS{hcddump}=="HCD Dump"
    ATTRS{gotgctl}=="GOTGCTL = 0x001c0001"
    ATTRS{spramdump}=="SPRAM Dump"
    ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306"
    ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a"
    ATTRS{gusbcfg}=="GUSBCFG = 0x20001700"
    ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406"
    ATTRS{devspeed}=="Device Speed = 0x0"
    ATTRS{fr_interval}=="Frame Interval = 0x1d4c"
    ATTRS{rem_wakeup_pwrdn}==""
    ATTRS{bussuspend}=="Bus Suspend = 0x0"
    ATTRS{buspower}=="Bus Power = 0x1"
    ATTRS{hnpcapable}=="HNPCapable = 0x1"
    ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 950 msecs (95 jiffies)"
    ATTRS{enumspeed}=="Device Enumeration Speed = 0x1"
    ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0"
    ATTRS{regoffset}=="0xffffffff"

  looking at parent device '/devices/platform/soc':
    KERNELS=="soc"
    SUBSYSTEMS=="platform"
    DRIVERS==""
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""

Learn more with the control vcgencmd

Command vcgencmd allows to retrieve information on the firmware of the Raspberry. Run the command vcgencmd commands to retrieve the full list of available commands. The list may change in each update of the Firmware. Some commands require an additional argument. To know in detail the functioning of each order, visit this page.

pi@raspberrypi:/sys/class/tty/ttyUSB0 $ vcgencmd commands
commands="vcos, ap_output_control, ap_output_post_processing, vchi_test_init, vchi_test_exit, pm_set_policy, pm_get_status, pm_show_stats, pm_start_logging, pm_stop_logging, version, commands, set_vll_dir, set_backlight, set_logging, get_lcd_info, arbiter, cache_flush, otp_dump, test_result, codec_enabled, get_camera, get_mem, measure_clock, measure_volts, scaling_kernel, scaling_sharpness, get_hvs_asserts, get_throttled, measure_temp, get_config, hdmi_ntsc_freqs, hdmi_adjust_clock, hdmi_status_show, hvs_update_fields, pwm_speedup, force_audio, hdmi_stream_channels, hdmi_channel_map, display_power, read_ring_osc, memtest, dispmanx_list, get_rsts, schmoo, render_bar, disk_notify, inuse_notify, sus_suspend, sus_status, sus_is_enabled, sus_stop_test_thread, egl_platform_switch, mem_validate, mem_oom, mem_reloc_stats, file, vctest_memmap, vctest_start, vctest_stop, vctest_set, vctest_get"

Let’s do some tests.

Know the temperature of the microprocessor, vcgencmd measure_temp

vcgencmd-measure_temp

The resolution of the monitor connected to the Raspberry, vcgencmd get_lcd_info

vcgencmd-get_lcd_info

Connect remotely using SSH

To learn more, read more complete previous article . Otherwise, after activating the SSH connection from raspi-config , use Putty (Windows) or open the Terminal command on Mac and Linux and run

 ssh pi@ADRESSE_IP_RPI

Or with the distribution Raspbian

 ssh pi@raspberrypi.local

the default password is raspberry .

Other useful commands

Knowing the services status

A service is a program that runs in the background and starts at system startup (Raspbian or any other Linux distribution). Use sudo –status-all to list the services launched. For example, we can check if MongoDB service is started (red box).

raspbian sudo --service-all mongodb runing

Other useful commands

sudo service <NOM_DU_SERVICE> status Service status
sudo service <NOM_DU_SERVICE> start Start the service
sudo service <NOM_DU_SERVICE> stop Stop the service
sudo service <NOM_DU_SERVICE> restart Restart the service (after a change in a configuration file for exemple)

Turn off the Raspberry

It lacks a button to stop his Raspberry! Here are several of useful commands to shut down the Raspberry cleanly. Let’s not forget that it is imperative turn off the Raspberry before unplugging his punishment to destroy the SD card. It would be a shame to have to reinstall everything.

the fastest command is sudo poweroff which will immediately stop the RPI. The equivalent of poweroff is sudo shutdown now.

 sudo poweroff

If you want to set a stop, for example at 10 pm before going to bed, use the command shutdown-h . For example

 sudo shutdown -h 22:00

To cancel the scheduled stop time, sudo shutdown-c .

Prevent the black screen of Raspbian Jessie

Standby screen annoys you, here’s how to stop it very simply. On the other hand, think about the planet, don’t forget to press the power button to stop your screen. He has one he at least! [

Run the following command to edit the file cmdline.txt and add consoleblank = 0 at the end of the line

 sudo nano /boot/cmdline.txt

restart the Raspberry to take into account the new setting.

Turn on keypad Num Lock from the start Raspbian

Strange thing, the keypad is not enabled by default at startup of Raspbian. As there is no setting in raspi-config to configure this, we’ll have to do it by hand. Open the file configuration of the keyboard which is located in the directory / etc/kbd/config

 sudo nano/etc/kbd/config

Go near the end of the file and remove the # in front of LEDS = + num .

Little trick by the way, you can turn the time display in the upper right of the console by removing the # in front of DO_VCSTIME = yes .

Save and restart Raspbian ( sudo reboot ) to take into account the new settings.

raspbian activer numlock vcstime

Update of Linux (and Raspbian)

There are two commands to update the system. The first apt – get update to update the packages of the current version (translation… files)

 sudo apt-get update

If you want to upgrade the packages to the latest version, we execute the command apt – get upgrade . This command allows to update the firmware of the Raspberry Pi for example.

 sudo apt-get upgrade

Finally update the distribution to each update of Raspbian for example. However there may also be some Python components manually update.

 sudo apt-get dist-upgrade

Voilà, I hope that these tips will be helpful. If you have others to share, the comments are there for that.

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

DIY Projects