Raspberry Pi commands that everyone should know
When working with a Raspberry Pi, it’s important to familiarize yourself with some of the essential Linux commands. These commands will help you navigate the system, manage files and directories, and gather important system information. In this article, we will cover a range of commands that every Raspberry Pi beginner should know.
What is Raspberry Pi ?
The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. It’s capable of doing everything you’d expect a desktop computer to do, from browsing the internet and playing high-definition video, to making spreadsheets, word-processing, and playing games. Read More…
In Linux, there are two types of user modes: one with basic access and the other with administrator access, also known as super user or root. Some tasks need administrator access to perform. To do these tasks, you need to use the sudo command before your regular commands. This tells the computer to run the command with administrator privileges.
Instead of typing sudo before each command, you can enter sudo su to access the root command prompt. This way, every command you type will automatically have administrator privileges.
Remember, there are lots of options for each command that I might not mention. To see all the options available for a command, just type the command followed by –help.
General Commands
apt-get update:
This command synchronizes the list of packages on your system to the list in the repositories. It’s important to run this command before installing new packages to make sure you are installing the latest version.
apt-get upgrade: Use this command to upgrade all of the software packages you have installed on your Raspberry Pi. It ensures that you have the latest versions of all your software.
clear: If your terminal screen is cluttered with previously run commands and text, you can use the clear command to clear the screen and start fresh.
date: This command prints the current date on your Raspberry Pi.
find / -name example.txt: If you’re looking for a specific file on your Raspberry Pi, you can use this command to search the entire system for the file “example.txt”. It will output a list of all directories that contain the file.
nano example.txt: If you need to edit a text file on your Raspberry Pi, you can use the nano command to open the file in the Linux text editor Nano.
poweroff: This command allows you to shut down your Raspberry Pi immediately.
raspi-config: Use this command to open the configuration settings menu on your Raspberry Pi. It provides a user-friendly interface to configure various settings.
reboot: If you need to reboot your Raspberry Pi, you can use this command to do it immediately.
shutdown -h now: This command allows you to shut down your Raspberry Pi immediately.
shutdown -h 01:22: If you want to schedule a shutdown at a specific time, you can use this command. For example, “shutdown -h 01:22” will shut down your Raspberry Pi at 1:22 AM.
startx: This command opens the GUI (Graphical User Interface) on your Raspberry Pi, allowing you to access the desktop environment.
File and Directory Commands
cat example.txt:
Use this command to display the contents of a file named “example.txt”. It’s a handy way to quickly view the contents of a text file.
cd /abc/xyz: This command changes the current directory to the “/abc/xyz” directory. It allows you to navigate through different directories on your Raspberry Pi.
cp XXX: If you need to copy a file or directory, you can use the cp command. For example, “cp examplefile.txt /home/pi/office/” copies the file “examplefile.txt” from the current directory to the “/home/pi/” directory. If the file is not in the current directory, you need to specify the full path of the file’s location.
ls -l: Use this command to list files in the current directory. It provides additional information such as file size, date modified, and permissions.
mkdir example_directory: This command creates a new directory named “example_directory” inside the current directory. It’s useful for organizing your files and directories.
mv XXX: The mv command allows you to move a file or directory to a specified location. For example, “mv examplefile.txt /home/pi/office/” moves the file “examplefile.txt” from the current directory to the “/home/pi/office” directory. You can also use this command to rename files within the same directory.
rm example.txt: Use this command to delete a file named “example.txt”. Be careful when using this command, as it permanently deletes the file.
rmdir example_directory: If you want to delete an empty directory named “example_directory”, you can use this command. It only works if the directory is empty.
scp user@10.0.0.32:/some/path/file.txt: This command allows you to copy a file over SSH. It can be used to download a file from a PC to your Raspberry Pi. Replace “user@10.0.0.32” with the username and local IP address of the PC, and “/some/path/file.txt” with the path and file name of the file on the PC.
touch example.txt: If you need to create a new, empty file named “example.txt” in the current directory, you can use this command.
Networking and Internet Commands
ifconfig:
Use this command to check the status of the wireless connection you are using. It displays information about the network interface, including whether it has acquired an IP address.
iwconfig: This command allows you to check which network the wireless adapter on your Raspberry Pi is using.
iwlist wlan0 scan: If you want to see a list of the currently available wireless networks, you can use this command.
nmap: The nmap command scans your network and lists connected devices, port numbers, protocols, states (open or closed), operating systems, MAC addresses, and other information.
ping: Use the ping command to test connectivity between two devices connected on a network. For example, “ping 10.0.0.32” will send a packet to the device at IP 10.0.0.32 and wait for a response. You can also use this command with website addresses.
wget http://www.website.com/example.txt: This command allows you to download a file from the web. It downloads the file “example.txt” from the specified URL and saves it to the current directory on your Raspberry Pi.
System Information Commands
cat /proc/meminfo:
Use this command to view details about your memory, including total memory, free memory, and more.
cat /proc/partitions: If you want to know the size and number of partitions on your SD card or hard drive, you can use this command.
cat /proc/version: This command shows you which version of the Raspberry Pi you are using.
df -h: Use this command to get information about the available disk space on your Raspberry Pi. It displays the total disk space, used space, and available space.
df /: If you only want to know how much free disk space is available on your Raspberry Pi, you can use this command.
dpkg –get-selections | grep XXX: This command shows all of the installed packages that are related to “XXX”. It’s useful for finding specific packages on your Raspberry Pi.
dpkg –get-selections: Use this command to view a list of all the installed packages on your Raspberry Pi.
free: This command shows how much free memory is available on your Raspberry Pi.
hostname -I: If you need to know the IP address of your Raspberry Pi, you can use this command.
lsusb: Use this command to list USB hardware connected to your Raspberry Pi.
UP key: Pressing the UP key will print the last command entered into the command prompt. This is a quick way to repeat previous commands or make corrections to commands.
vcgencmd measure_temp: If you’re curious about the temperature of the CPU on your Raspberry Pi, you can use this command to find out.
vcgencmd get_mem arm: This command displays the amount of memory allocated to the ARM processor on your Raspberry Pi.
These are just a few of the essential Linux commands that every Raspberry Pi beginner should know. By familiarizing yourself with these commands, you’ll be able to navigate your Raspberry Pi more efficiently and perform a wide range of tasks. Happy experimenting!