Raspberry Pi | Linux Commands

Click the above “Mechanical and Electronic Engineering Technology” to follow us
1. System Management
Update the package list:
sudo apt update
Upgrade installed packages:
sudo apt upgrade
Install new packages:
sudo apt install <package_name>
Remove packages:
sudo apt remove <package_name>
Clean up unnecessary packages and cache:
sudo apt autoremove
Find packages:
apt search <keywords>
View installed package information:
dpkg -l
Shut down:
sudo shutdown now
Restart:
sudo reboot
View system information (including hardware information):
uname -a
View disk usage:
df -h
View memory usage:
free -h
2. File Management

Change directory:

cd <directory_path>

List files and folders in the current directory:

ls

Display detailed information (including permissions, owner, size, etc.):

ls -l

Create a new folder:

mkdir <directory_name>

Create a new file:

touch <file_name>

Copy files or folders:

cp <source> <destination>

Move files or folders:

mv <source> <destination>

Delete files:

rm <file_name>

Delete folders and their contents:

rm -r <directory_name>

View file contents:

cat <file_name>

Edit files:

nano <file_name>

Compress files or folders:

tar -czvf <archive_name.tar.gz> <folder_or_file_to_compress>

Decompress files:

tar -xzvf <archive_name.tar.gz>
3. Software Management

Update the package list:

sudo apt update

Upgrade installed packages:

sudo apt upgrade

Search for available packages:

apt search <keywords>

Install packages:

sudo apt install <package_name>

Uninstall packages:

sudo apt remove <package_name>

Clean up unnecessary packages and cache:

sudo apt autoremove

Display installed package information:

dpkg -l

List detailed information of a specific package:

apt show <package_name>

Find the file path of a package:

dpkg -L <package_name>

Lock/unlock package versions:

sudo apt-mark hold <package_name>sudo apt-mark unhold <package_name>

Check package dependencies:

apt depends <package_name>
4. Performance Monitoring

View system load and uptime:

uptime

View current memory usage:

free -h

View current CPU usage:

top

View overall CPU usage:

mpstat

View disk space usage:

df -h

Monitor network traffic:

iftop

Monitor real-time process status:

htop

View temperature sensor data (requires Raspberry Pi to have this feature):

vcgencmd measure_temp
5. Common Operations
View Raspberry Pi model
cat /proc/cpuinfo
View system version
sudo lsb_release -a
Change system source

Open the terminal window, you can connect via VNC or open directly on Raspberry Pi.

Edit the /etc/apt/sources.list file, you can open it with any text editor, for example, using the nano editor:

sudo nano /etc/apt/sources.list

In the opened file, find and comment out the original source for backup. The way to comment is to add a hash (#) at the beginning of the source line, for example:

# deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

Add a new system source. You can choose a suitable mirror source and add it to the end of the file. Here is an example:

deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib

Press Ctrl + X, then enter Y to save changes, and finally press Enter to confirm saving.

Update the package list:

sudo apt update

After completing the update, you can use the new system source to install, update, and upgrade packages.

Change pip source
Edit the ~/.pip/pip.conf file. If this file does not exist, you can create it using the following command:
mkdir -p ~/.pip touch ~/.pip/pip.conf
Use any text editor to open the ~/.pip/pip.conf file, for example, using the nano editor:
nano ~/.pip/pip.conf
In the opened file, add or modify the following content to set the new pip source. Here is an example:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Press Ctrl + X, then enter Y to save changes, and finally press Enter to confirm saving.
Raspberry Pi | Linux Commands

Want to know more

Quickly scan the code to follow

Leave a Comment