Raspberry pi BasicsStarter Guide

Raspberry Pi Programming- Most Useful Commands

In this quick tutorial you will find the most basic and the useful commands for Raspberry PI running a Linux Based OS. As, you know most of the PI OS is Linux based.

Before, moving ahead we should note that there are two user modes for using the command terminal on LINUX that is User Privileges. One user mode has basic access privileges, and the other mode has administrator access privileges. Some tasks can’t be performed with basic privileges, so we need to enter them with super user privileges to perform them.

We frequently see the prefix sudo before commands, which means we are telling the computer to run the command with super user privileges..

An alternative to entering sudo every time before each command is to access the root command prompt, which runs every command with administrator/super user privileges.

For root access mode type sudo su at the command terminal. After entering sudo su, you’ll see the root@raspberrypi:/home/pi# command prompt, and all subsequent commands will now have super user privileges.

Most of the commands mentioned below have a lot of other useful options that we have not mentioned.

To see a list of all the other available options for a command, enter the command, followed by – –help.

General Commands:

 

apt-get update

Synchronizes the list of packages on your system to the list in the repositories. Use it before installing any new packages. Make sure that you are installing the latest version.

clear

Clears previously used commands and text from the terminal screen.

apt-get upgrade

Upgrades all of the packages of software installed.

date

Prints the current date to the command terminal

find / -name sample.txt

Searches the whole system for the file sample.txt and outputs a list of all directories that contain the file.

nano sample.txt

Opens the file sample.txt in the Linux text editor Nano.

raspi-config

Opens the Configuration Settings Menu

startx

Opens the Graphical User Interface (GUI) window.

Poweroff

Or   shutdown -h now

 For shutdown the system immediately

shutdown -h 10:30

To shutdown the system at 10:30 AM

 

Directory and File related Commands:

ls -l

To show a list of files in the current directory, along with file size, date modified, and permissions

Mkdir sample_directory

Creates a new directory named sample_directory inside the current directory.

mv ABCD

Moves the file or directory named ABCD to a specified location. For example, mv samplefile.txt /home/pi/office/ moves examplefile.txt in the current directory to the /home/pi/office directory. If the file is not in the current directory, add the path of the file’s location (i.e. cp /home/pi/documents/samplefile.txt )

cat sample.txt

To display the contents of the file sample.txt

cd /abcd/xyz

For Changing the current directory to the /abcd/xyz directory

rmdir sample_directory

Command for removing or deleting the directory sample_directory (if it is empty)

rm sample.txt

To delete or remove the file naming sample.txt

touch example.txt

Creates a new and empty file naming  example.txt in the current directory.

scp user@10.0.0.31:/some/path/file.txt

Copies a file over SSH. Can be used to download a file from a PC to the Raspberry Pi. user@10.0.0.31 is the Username and Local IP address of the computer, and /some/path/file.txt is the path and file name of the file on the computer..

 

System Related commands:

        cat /proc/meminfo

To show the details about system’s memory.

      cat /proc/version

 

Shows which version of the Raspberry Pi is being used.

        df -h

Display informations about the available disk space.

cat /proc/partitions

Shows the size and number of partitions on SD card or the external Hard-drive

         df /

Shows free available disk space  .

dpkg – –get–selections | grep ABC

Shows all of the installed packages that are related to ABC

dpkg – –get–selections

Shows all installed packages on the system

hostname -I

Shows the IP address of Raspberry Pi

lsusb

Shows the list of all USB hardware connected to Raspberry Pi

vcgencmd measure_temp

Shows the current temperature of the CPU.

vcgencmd get_mem arm && vcgencmd get_mem gpu

Shows how the memory is split between the CPU and GPU

free

Shows how much free memory is available

 

Networking Realated PI Commands:

ping

It tests the connectivity between two devices connected on a network. For example, ping 10.0.0.31 will send a packet to the device at IP 10.0.0.31 and wait for a response and if the response is received it displays- Ping successful. Ping command also works with website addresses ex- ping www.roboshala.com

nmap

Scans network and lists

all connected devices, port number, protocol, state (open or closed) operating system, MAC addresses, and with other relevant information

iwlist wlan0 scan | grep ESSID

Use grep along with the name of a field to list only the fields you need (for example to just list the ESSIDs).

ifconfig

Checks the status of the wireless connection Raspberry Pi is using.

iwconfig

Checks for the network the wireless adapter is using

iwlist wlan0 scan

To print a list of all the currently available wireless networks
wget   https://www.roboshala.com/sample.txt
Downloads the file sample.txt from the roboshala.com and saves it to the current directory.

 

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close