The ultimate Raspberry Pi commands

July 8, 2024 by
The ultimate Raspberry Pi commands
Boot & Work Corp. S.L., Martí Schnabel

Introduction

Raspberry Pi commands serve various purposes, enabling users to interact with the operating system (usually Raspbian, a Debian-based Linux distribution), configure settings, manage files, and perform various tasks.

This blog post is a continuation of Most Useful Commands for Raspberry Pi automation post. Here you will learn some more really useful tools to use on your Raspberry Pi or Raspberry PLC in a safe environment

Alias

The alias command is used to create shortcuts or alternative names for commands. It allows you to define your own custom command names or modify existing ones to suit your preferences. Aliases are particularly useful for simplifying complex or frequently used commands, making the command-line interface more efficient and user-friendly.

Here's the basic syntax of the alias command:

alias new_command='original_command'
  • new_command: This is the alias you're creating. It's the custom name you want to use for the command.
  • original_command: This is the actual command or set of commands that the alias represents. It is enclosed in single quotes to ensure that the alias is interpreted correctly.

For example, let's say you frequently use the ls -l command to list files with detailed information. You can create an alias like this:

alias ll='ls -l'

Now, whenever you type ll in the terminal, it will be equivalent to typing ls -l. To view a list of your current aliases, you can simply type the alias command without any arguments.


To remove an alias, you can use the unalias command followed by the alias name:


unalias ll


However, keep in mind that aliases are usually temporary and are only active for the duration of your shell session. If you want to make an alias permanent, you can add the alias command to your shell configuration file (e.g., ~/.bashrc for Bash) so that it's loaded every time you start a new shell session.

How2

How2 is a brad new powerful tool that uses advanced artificial intelligence to make the Unix Terminal easier to use. It's designed for people who work with commands in the Bash or Zsh shell. Its main job is to help users quickly write Bash scripts and improve their command-line work.

Execute this command to install it:

sudo npm install -g how-2

This command has many potential uses, and here are two examples:

1. It can give you information about how to perform different actions using the command line:

​2. It can create scripts that you can run yourself. However, it doesn't run them automatically to ensure safety:

Netstat

The netstat command in Linux is a powerful utility for displaying information about various aspects of networking. It provides details on network connections, routing tables, interface statistics, and more. Administrators and users frequently use netstat to troubleshoot network-related issues, monitor network activity, and gain insights into the status of active connections.

By utilizing different options, such as -t for TCP connections or -u for UDP connections, users can focus on specific aspects of network information. The command's versatility and ability to reveal real-time network details make it an essential tool for system administrators and network analysts.

For example, the netstat -tl command in Linux is used to display a list of all listening TCP connections. This is particularly useful for identifying which network services are actively listening for incoming connections on the system. The -t option specifies that only TCP connections should be displayed, and the -l option indicates that the command should show only listening sockets. Check man netstat to see more options.


Process management

The ps, kill, and killall commands are used for process management and viewing information about running processes, terminating processes, and killing multiple processes, respectively.

The ps command is used to display information about the currently running processes. It provides a snapshot of the system's processes at the time the command is executed. The command can be customized to show various details about each process, such as the process ID (PID), the terminal associated with the process, the CPU and memory usage, and more.

This command is used for monitoring processes, identifying resource-intensive tasks, and diagnosing system issues. It helps administrators and users understand which processes are running and how they are utilizing system resources.

Free

The free command is used to display information about the system's memory usage. It provides information about both physical and swap memory, including the total amount of available, used, and free memory. The free command is helpful for monitoring the system's memory usage and identifying potential performance issues related to memory.

Without any options, the free command displays information in kilobytes, including the total, used, and free memory for both physical and swap memory. Although, there can be used some options to display the memory sizes in different units as -e, -b, -k, -m and -g.

It is a very useful command to know if you are running out of memory in your RPi. Here is a sample output:

  • total: Total physical memory.
  • used: Memory used by the system.
  • free: Free (unused) memory.
  • shared: Memory used by tmpfs and similar kernel resources.
  • buffers: Memory used for buffering I/O operations.
  • cached: Memory used for caching files.

The available column represents an estimate of how much memory is available for starting new applications without swapping. It's a more realistic measure of the actual available memory for applications.

Some peculiar commands

Yes

The yes command is a simple utility that continuously outputs the string "y" or a user-specified string, followed by a newline, to the terminal. Its primary purpose is to simulate a user continuously pressing the "yes" key when prompted by a command or script, effectively automating confirmation processes.


Whoami

The whoami command is used to display the username of the current user. This can be helpful in scripts or command-line operations where you need to identify the current user without having to check system files or environment variables manually. The output is a simple display of the username associated with the active session. In a Raspberry Pi, the most common default user is "pi".

Cal

The cal command in Linux is a simple utility that displays a calendar for the current month or a specified month and year. When you run cal without any arguments, it shows the calendar for the current month. It's a quick way to check dates and days of the week directly from the command line.


​Search in our Blog

The ultimate Raspberry Pi commands
Boot & Work Corp. S.L., Martí Schnabel July 8, 2024
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>