Commonly Used Commands on Raspberry Pi

When working with Raspberry Pi, mastering some basic Linux commands will help you navigate and control the system efficiently. Whether you’re managing files, installing software, or monitoring system performance, knowing these commonly used commands is essential. This guide will introduce you to the most commonly used commands on Raspberry Pi, perfect for beginners to get started with the command line.

Why Learn Basic Raspberry Pi Commands?

  • Faster Navigation: The terminal allows for quick file navigation and management without needing to rely on the graphical interface.
  • System Control: Commands enable full control over your Raspberry Pi, letting you install software, monitor performance, and troubleshoot issues.
  • Automation: With terminal commands, you can create scripts to automate repetitive tasks.

Basic File and Directory Commands

These commands are essential for navigating and managing files and directories on your Raspberry Pi.

1. ls (List Files and Directories)

The ls command lists all files and directories in the current directory.

  • List all files: ls
  • List with detailed information (permissions, owner, file size, etc.): ls -l
  • Include hidden files (files that start with a .): ls -a

2. cd (Change Directory)

Use the cd command to move between directories.

  • Navigate to a specific directory: cd /home/pi/Documents
  • Return to the home directory: cd ~
  • Move up one level in the directory structure: cd ..

3. mkdir (Make Directory)

To create a new directory, use the mkdir command.

  • Create a new directory: mkdir newfolder

4. rm (Remove Files and Directories)

The rm command deletes files and directories. Be careful, as this action is permanent.

  • Remove a file: rm filename.txt
  • Remove a directory and its contents: rm -r myfolder

5. cp (Copy Files and Directories)

The cp command copies files and directories.

  • Copy a file: cp file.txt /home/pi/Desktop
  • Copy a directory and its contents: cp -r myfolder /home/pi/Documents

6. mv (Move or Rename Files and Directories)

Use mv to move or rename files and directories.

  • Move a file: mv file.txt /home/pi/Documents
  • Rename a file: mv oldname.txt newname.txt

System Information Commands

These commands help you gather information about your Raspberry Pi system, such as hardware, network, and performance details.

7. uname (System Information)

The uname command displays system information.

  • Show the system kernel name: uname
  • Show detailed system information: uname -a

8. df (Disk Space Usage)

The df command shows the disk space usage of your system.

  • Display disk space usage for all file systems: df -h

9. top (System Monitor)

The top command shows real-time information about system processes, including CPU and memory usage.

  • Run the system monitor: top
  • To exit, press q.

10. free (Memory Usage)

The free command shows information about available and used system memory (RAM).

  • Display memory usage: free -h

11. vcgencmd measure_temp (CPU Temperature)

This command shows the current CPU temperature of your Raspberry Pi.

  • Check CPU temperature: vcgencmd measure_temp

Software Installation and Updates

These commands are essential for keeping your Raspberry Pi’s software up to date and installing new packages.

12. sudo apt update (Update Package Lists)

Before installing or upgrading software, it’s important to update your Raspberry Pi’s package lists.

  • Update package lists: sudo apt update

13. sudo apt upgrade (Upgrade Installed Software)

This command upgrades all installed software to the latest available versions.

  • Upgrade installed packages: sudo apt upgrade -y

14. sudo apt install (Install New Software)

The apt install command allows you to install new software packages.

  • Install a package (for example, the vim text editor): sudo apt install vim

15. sudo apt remove (Remove Installed Software)

To uninstall or remove a package, use the apt remove command.

  • Remove a package: sudo apt remove package_name

Networking Commands

These commands are useful for managing and troubleshooting network connections on your Raspberry Pi.

16. ifconfig (Network Configuration)

The ifconfig command displays the current network configuration of your Raspberry Pi.

  • Show network interfaces and IP addresses: ifconfig

17. ping (Test Network Connection)

Use the ping command to test your network connection by sending packets to a specific server.

  • Ping a server (e.g., Google): ping google.com
  • Stop the ping with Ctrl + C.

18. hostname -I (Show IP Address)

This command shows the IP address of your Raspberry Pi.

  • Display the IP address: hostname -I

19. netstat (Network Statistics)

The netstat command displays network connections and routing tables.

  • Show active network connections: netstat

File Editing Commands

These commands are used to create, view, and edit files directly from the terminal.

20. nano (Text Editor)

nano is a simple terminal-based text editor for creating or editing text files.

  • Open or create a file with nano: nano filename.txt
  • Use Ctrl + O to save and Ctrl + X to exit.

21. cat (View File Contents)

The cat command displays the contents of a text file.

  • View a file: cat filename.txt

22. tail (View End of File)

The tail command shows the last few lines of a file (useful for logs).

  • Show the last 10 lines of a file: tail filename.txt
  • Show continuous updates (useful for logs): tail -f /var/log/syslog

FAQ: Commonly Used Commands on Raspberry Pi

Q: Can I undo a command in the terminal?
A: Unfortunately, there’s no “undo” command in the terminal. It’s important to double-check commands, especially when using rm or sudo.

Q: How do I find out what a command does before running it?
A: You can use the man (manual) command to learn more about most commands. For example: man ls

Q: How do I stop a running command?
A: You can stop most running commands by pressing Ctrl + C.

Conclusion:

By learning these commonly used commands on Raspberry Pi, you’ll have the tools needed to navigate, manage, and control your Raspberry Pi efficiently. Whether you’re installing software, managing files, or checking system performance, these basic commands provide a strong foundation for using Raspberry Pi.