Debian tutorial¶
Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.
This guide is designed for beginners using the Quectel Pi H1 smart single-board computer, helping users quickly get up to speed with essential Debian operations and common development workflows. Covering file attributes and permissions, file management, text editing, and package management, it provides a step-by-step onboarding path for users with little to no Linux experience.
File attributes and permissions¶
Understand Linux file types, ownership, and permission bits. Learn how to inspect file attributes using ls -l and manage file ownership and access permissions with chown and chmod.
In Linux, a file consists of much more than just a name and size; it also carries metadata including owner, group, access permissions, file type, and modification timestamp. Understanding these attributes helps troubleshoot common issues such as scripts failing to execute, directories lacking write permissions, and requiring sudo privileges when editing system configuration files.
How to view file attributes¶
The most common way to view file attributes is as follows:
ls -l
A typical output is shown below:
-rwxr-xr-- 1 user user 2048 Jun 22 10:30 demo.sh
This information can be split into the following parts:
Field |
Example |
Description |
|---|---|---|
File type and permissions |
-rwxr-xr-- |
The first character indicates the file type, and the remaining nine characters indicate permissions. |
Number of links |
1 |
The number of directory entries pointing to the file. |
Owner |
user |
File owner. |
Group |
user |
The group that owns the file. |
Size |
2048 |
File size. Unit: bytes (default). |
Modification time |
Jun 22 10:30 |
Last modification time. |
File name |
demo.sh |
File name. |
To display hidden files and show file sizes in a human-readable format, run the following command:
ls -lah
Where:
-a (All): Forces the listing of hidden files and special directory entries. When executed in any directory, the first two lines of output will always include . (current directory) and .. (parent directory).
-h (Human-readable): Converts byte counts into human-readable units (e.g., 2.0K, 4.5M), so file sizes are no longer displayed as raw byte values.
Typical output:
total 68K
drwxrwxr-x 5 pi pi 4.0K Sep 23 15:42 .
drwx------ 21 pi pi 4.0K Sep 23 15:42 ..
drwxrwxr-x 2 pi pi 4.0K Sep 23 15:42 assets
drwxrwxr-x 8 pi pi 4.0K Sep 23 15:42 .git
-rw-rw-r-- 1 pi pi 82 Sep 23 15:42 .gitignore
-rwxrwxr-x 1 pi pi 5.2K Sep 23 15:42 install.sh
-rw-rw-r-- 1 pi pi 9.0K Sep 23 15:42 README.md
-rw-rw-r-- 1 pi pi 8.5K Sep 23 15:42 README_zh.md
-rw-rw-r-- 1 pi pi 98 Sep 23 15:42 requirements.txt
-rw-rw-r-- 1 pi pi 3.2K Sep 23 15:42 setup_autostart.sh
drwxrwxr-x 2 pi pi 4.0K Sep 23 15:42 src
-rw-rw-r-- 1 pi pi 509 Sep 23 15:42 start.sh
File type identification¶
The first character in the permission string indicates the file type:
For example:
drwxr-xr-x: Directory.
-rw-r--r--: Regular file.
lrwxrwxrwx: Symbolic link.
Permission bit structure description¶
The nine characters from positions 2 through 10 are divided into three groups:
rwx r-x r--
| | |
| | +-- Other users (others) permissions
| +------ Group (group) permissions
+---------- Owner (owner) permissions
Each set of permissions contains the following characters:
Symbol |
Meaning |
|---|---|
r |
Readable |
w |
Writable |
x |
Executable |
- |
No permission |
For example:
rw-r--r--: The owner can read and write the file, while the group and other users can only read it.
rwxr-xr-x: The owner can read, write, and execute the file, while the group and other users can read and execute it.
chown: manage owner and group¶
If a file is owned by the wrong user or group, use chown to update it.
Basic syntax:
sudo chown [options] user[:group] file_or_directory
Common examples:
Change the file owner to the currently logged-in user:
sudo chown "$USER" demo.sh
Change both the owner and group:
sudo chown "$USER":"$USER" demo.sh
Recursively change the owner and group of the directory:
sudo chown -R "$USER":"$USER" "$HOME"/project
Change only the group:
sudo chown :"$USER" /home/"$USER"/project/config.json
Quectel Pi H1 typical application scenarios
After files are extracted or copied using sudo, their owner becomes root, preventing the regular user from editing them.
If the permissions of a project directory copied from an external device do not match those of the current user, adjust them accordingly.
chmod: manage access permissions¶
Use chmod when a file is readable but not writable, or when a script cannot be executed.
Basic syntax:
chmod [options] permissions file_or_directory
Common options:
-R: Recursively applies permission changes to directories and all of their contents.
-v: Verbose mode; outputs diagnostic details for every file processed.
Symbolic mode
The format is as follows:
[ugoa][+-=][rwx]
Where:
u represents the owner.
g indicates the group.
o means other users.
a means all users.
Common examples:
Add execute permissions for the owner:
chmod u+x demo.sh
Add read permission for all users:
chmod a+r demo.txt
Remove write permissions for other users:
chmod o-w demo.txt
Numeric mode
Permissions can also be expressed in numerical form, for example:
chmod 755 demo.sh
chmod 644 notes.txt
The three digits correspond to:
chmod 755 demo.sh
| | |
| | +-- Other users (others) permissions
| +---- Group (group) permissions
+------ Owner (owner) permissions
Each rwx group consists of three permission bits: r, w, and x.
Is r (read permission) enabled?
Is w (write permission) enabled?
Is x (execution permission) enabled?
These three permission bits can be represented either by additive values or as a three-bit binary number:
The corresponding relationship is as follows:
Permission bit |
Binary bit |
Decimal weight |
|---|---|---|
r |
100 |
4 |
w |
010 |
2 |
x |
001 |
1 |
Thus, the numeric value of a permission set is simply the sum of the weights of all enabled permission bits:
Permissions |
Binary |
Octal |
|---|---|---|
--- |
000 |
0 |
--x |
001 |
1 |
-w- |
010 |
2 |
-wx |
011 |
3 |
r-- |
100 |
4 |
r-x |
101 |
5 |
rw- |
110 |
6 |
rwx |
111 |
7 |
Example¶
Add execution permissions to the script
chmod u+x start.sh
./start.sh
Protect private configuration files
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config
File and directory management¶
Master essential Linux commands for managing files and directories—pwd, cd, ls, mkdir, rmdir, cp, rm, and mv—along with file inspection utilities such as cat and tail.
In Linux, most day-to-day workflows revolve around paths and directories. Whether checking logs, switching project directories, copying model files, or cleaning up unused resources, you will rely on these core file and directory commands.
Path and directory fundamentals¶
Current working directory¶
A terminal session always has a current working directory. Most commands work in the current directory by default, so it's important to know the location.
View the current directory:
pwd
Once executed, the terminal outputs the absolute path of the current working directory, for example:
/home/user/project
Path representation¶
Absolute path: Start from the root directory /, such as /home/user/project.
Relative path: Relative to the current directory, such as project/src.
Common special notations:
.indicates the current directory.
..represents the parent directory.
~represents the current user’s home directory, such as /home/user.
Commonly used system directories¶
In Debian, users commonly work with the following directories:
Directory |
Function |
|---|---|
/etc |
System configuration file. |
/opt |
Third-party applications or custom programs. |
/var/log |
System log. |
/tmp |
Temporary files. |
Common commands¶
ls: list directory contents¶
The ls command displays the files and subdirectories contained within a directory. By default, it targets the current working directory, but you can pass any relative or absolute path to inspect a specific directory.
Examples:
# List contents of the current directory
ls
# List contents of the /var/log directory
ls /var/log
# List all files, including hidden files
ls -la
# Display human-readable file sizes
ls -lh
# Sort files by modification time (reverse chronological order)
ls -ltr
cd: change directories¶
The cd command changes the current working directory to the specified path.
cd [dirName]
# dirName: target directory, which can be a relative path or an absolute path.
Examples:
# Switch to the usr directory
cd /usr
#Return to the parent directory
cd ..
# Return to user home directory
cd ~
# Return to the previous working directory
cd -
mkdir and rmdir: create and delete directory¶
The mkdir command creates a directory, while rmdir removes an empty directory.
# -p ensures that the directory path exists, if it does not exist it will be created automatically
mkdir [-p] dirName
# -p If the parent directory becomes empty due to deletion of subdirectories, delete them together.
rmdir [-p] dirName
Examples:
# Create a logs directory in the current directory
mkdir logs
# Automatically create non-existent parent directory project/data
mkdir -p project/data/raw
# Delete the logs directory, which must be empty
rmdir logs
cp: copy files and directories¶
The cp command copies files or directories from a source location to a target destination.
cp [options] <source>... <destination>
cp supports passing multiple source paths to copy them into a single destination directory. Common options include:
-r: Recursively copies directories and their contents.
-i: Prompts for confirmation before overwriting an existing destination file (interactive mode).
-a: Archive mode; fully preserves file ownership, permission bits, timestamps, and soft/hard links.
Examples:
# Copy source.txt to backup.txt
cp source.txt backup.txt
# Copy a directory
cp -r project project_backup
# Archive copy, preserving ownership, permissions, and timestamps
cp -a project project_backup
mv: move and rename¶
The mv command is used to rename files and directories or move them to a different location.
Syntax:
mv [options] <source>... <destination>
-b: Creates a backup of the destination file or directory before overwriting it.
-i: Prompts for confirmation before overwriting an existing destination file (enter y to overwrite, n to cancel).
-f: Forces overwriting of existing files without prompting.
-n: Do not overwrite any existing file or directory (no-clobber).
-u: Moves only when the source file is newer than the destination file or when the destination file is missing.
# Move app.log to the /tmp/ directory
mv app.log /tmp/
# Rename old_name.txt to new_name.txt
mv old_name.txt new_name.txt
# Rename the dataset directory to dataset_old
mv dataset dataset_old
rm: remove files and directories¶
The rm command removes files or directories.
Syntax:
rm [options] <file_or_directory>
-i: Prompts for confirmation before removing each file.
-f: Forces removal without prompting, even if files are read-only.
-r: Recursively removes directories and their contents.
# Remove demo.txt
rm demo.txt
# Remove the demo_dir directory and its subdirectories
rm -r demo_dir
# Force remove without prompting
rm -rf demo_dir
Note
rm -rf is a destructive, high-risk command—deleted data cannot be recovered. Before running it, verify your target path using pwd and ls.
cat and tail: view file contents¶
cat:
The cat command concatenates files and prints them to standard output (stdout), making it ideal for viewing and combining file contents.
# View the contents of README.md
cat README.md
# Display file contents with line numbers
cat -n app.py
# Concatenate multiple files and redirect the output into a new file
cat part1.txt part2.txt > merged.txt
Tip: The cat outputs the entire contents of a file to the terminal all at once. When inspecting large log files or datasets (e.g., hundreds of megabytes), use less or more to paginate through the output (press q to exit) to prevent your terminal from freezing.
tail:
The tail command displays the end of a file.
# View the last 10 lines of a file by default (using the dpkg install log as an example)
tail /var/log/dpkg.log
# Output the last 50 lines (-n flag)
tail -n 50 /var/log/dpkg.log
# Stream and follow newly appended log lines in real time (-f flag)
tail -f ~/my_project/app.log
Tip: Running tail -f keeps the terminal session open to monitor log output in real time. To stop following and return to the shell prompt, press Ctrl + C.
Basic operation examples¶
Create and enter a project directory¶
# Create the project directory
mkdir -p ~/project/demo
# Navigate to the project directory
cd ~/project/demo
# # Print the current working directory (outputs /home/<username>/project/demo)
pwd
Back up configuration files¶
# Interactively prompt before overwriting if the destination file already exists (-i), preventing accidental overwrites of existing backups
cp -i /etc/hosts ~/hosts.bak
Clean up temporary directory¶
# Create a temporary directory for demonstration
mkdir -p ~/project/demo/tmp
# Remove the directory
rm -r ~/project/demo/tmp
Text editing¶
When developing on the Quectel Pi H1, you will frequently need to modify configuration files, edit scripts, or adjust service parameters. The most common terminal-based text editors are Vim and nano. This section introduces both editors so you can choose the right tool for your workflow.
Vim editor¶
Vim is an enhanced version of the vi editor, offering syntax highlighting, search-and-replace, and batch editing capabilities. It works seamlessly across local terminals, serial consoles, and SSH sessions.
If the command is not found, install it by running:
sudo apt update
sudo apt install vim -y
Vim modes¶
Vim operates in three core modes:
Mode |
Function |
How to enter |
|---|---|---|
Normal mode |
Navigate the cursor, copy (yank), and delete text |
Active by default upon opening a file |
Insert mode |
Type and edit text |
Press i, a, or o from Normal mode |
Command-line mode |
Execute commands such as save, quit, and search-and-replace |
Press : from Normal mode |
The transition workflow between these modes is as follows:
Opening a file enters Normal mode by default.
Switch to Insert mode when you need to enter or edit text.
Switch to Command-line mode when you need to save, exit, or run search-and-replace commands.
Basic operations¶
Open or create a file
vim notes.txt
If the file doesn't exist, Vim opens a new buffer in memory and only creates the file on disk once you save.
Enter Insert mode
Press any of the following keys in Normal mode:
Key |
Function |
|---|---|
i |
Enter Insert mode at the current cursor position. |
a |
Enter Insert mode after the current cursor position. |
o |
Open a new line below the current line and enter Insert mode. |
Text entry
After entering Insert mode, you can enter characters like a normal editor.
Return to Normal mode
Press the Esc key to return to Normal mode.
Save and exit
In Normal mode, press : to enter Command-line mode, and then enter and execute the appropriate command:
Command |
Function |
|---|---|
:w |
save |
:q |
Exit |
:wq |
Save and exit |
:q! |
Do not save, force quit |
Common operating instructions¶
Common instructions in Normal mode
Key |
Function |
|---|---|
h j k l |
Move cursor left, down, up, right |
x |
Delete current character |
dd |
Delete the current line |
yy |
copy current line |
p |
Paste |
u |
Undo |
Ctrl+r |
Redo |
/keyword |
Search forward |
n |
Jump to next match |
Common commands in Command-line mode
Command |
Function |
|---|---|
:set nu |
Show line numbers |
:set nonu |
Hide line numbers |
:%s/old/new/g |
Replace all occurrences in the file |
:1,10s/old/new/g |
Replace lines 1 to 10 |
Example¶
The following is an example of creating a simple script:
vim hello.sh
Press i to enter Insert mode, and then enter the following content:
#!/bin/bash
echo "Hello Quectel Pi H1"
Press Esc to return to Normal mode, press enter, and type :wq to save and exit.
Next, grant execute permissions to the script:
chmod u+x hello.sh
./hello.sh
Expected terminal output:
Hello Quectel Pi H1
Edit system files¶
To edit a file in a regular user's home directory, run:
vim ~/notes.txt
When editing system configuration files, elevated privileges via sudo are typically required. It is recommended to back up the original file before making changes:
# Back up using -a (archive mode) to preserve exact permissions, ownership, and timestamps
sudo cp -a /etc/hostname /etc/hostname.bak
# Edit the configuration file
sudo vim /etc/hostname
Troubleshooting¶
Cannot exit Vim
This typically happens when you are still in Insert mode. Press Esc to return to Normal mode, then type :q or :wq.
"Permission denied" on save
This indicates that modifying the file requires elevated (root) privileges. Exit Vim and reopen the file using sudo vim <filename>.
Unexpected Indentation
This occurs when Vim's autoindent conflicts with pasted clipboard text, or when tabstop, shiftwidth, and tab expansion settings are mismatched. Fix: In Normal mode, run :set paste before pasting your text. Once finished, run :set nopaste to disable it.
Chinese characters displaying incorrectly
This is usually caused by terminal font settings or mismatched file encodings. We recommend using UTF-8 encoding and verifying that your graphical terminal emulator uses a font with Chinese character support.
nano editor¶
Overview¶
nano is a lightweight terminal text editor with a simple and intuitive interface. It requires no mode switching, making it suitable for quickly editing configuration files and for users who are unfamiliar with Vim.
If nano is not installed, run the following commands:
sudo apt update && sudo apt install -y nano
Basic operations¶
Open or create a file
nano notes.txt
If the file doesn't exist, nano opens an in-memory buffer and creates the file when you save. You can begin typing and editing immediately without switching modes.
Edit text
After opening the file, you can directly enter characters at the cursor position and use the arrow keys to move the cursor.
Save file
Press Ctrl+O (the letter O), nano will prompt to confirm the file name, press Enter key to confirm saving.
Exit editor
Press Ctrl+ X to exit. If there are unsaved modifications to the file, nano will ask whether to save them:
Pressing Y displays the prompt File Name to Write: notes.tx t; press Enter to confirm the filename, save, and exit.
Press N to exit without saving.
Press Ctrl+C to cancel the exit operation.
Commonly used shortcut keys¶
nano displays common keyboard shortcuts at the bottom of the screen. The ^ symbol represents the Ctrl key. The M- represents the Alt key.
Shortcut keys |
Function |
|---|---|
Ctrl + O |
Save file |
Ctrl + X |
Exit |
Ctrl + K |
Cut current line |
Ctrl + U |
Paste the cut content |
Ctrl + W |
Search text |
*Ctrl + * |
Search and replace |
Ctrl + G |
View help |
Ctrl + C |
Show current cursor position/ Cancel current operation |
Alt + U |
Undo |
Alt + E |
Redo |
Ctrl + A |
Move to beginning of line |
Ctrl + E |
Move to end of line |
Ctrl + Y |
Page up (or use the PageUp key) |
Ctrl + V |
Page down (or use the PageDown key) |
Search and replace¶
Search text
Press Ctrl+ W, enter the search term, and press Enter to jump to the first match. Press Ctrl+ W and Enter again to jump to the next match.
Search and replace
Press Ctrl+ ****, enter the search string, and press Enter. Then enter the replacement string and press Enter again. The nano editor will prompt you to confirm each replacement:
Press Y to replace the current match.
Press N to skip the current match.
Press A to replace all matches.
Example¶
Take creating a simple script as an example:
nano hello.sh
Enter the following directly:
#!/bin/bash
echo "Hello Quectel Pi H1"
Press Ctrl+ O to save, press Enter to confirm the filename, and then press Ctrl+ X to exit.
Next, grant execute permissions to the script:
chmod u+x hello.sh
./hello.sh
Expected terminal output:
Hello Quectel Pi H1
Edit system files¶
When editing system configuration files, elevated privileges via sudo are likewise required:
# Back up in archive mode to preserve permissions, ownership, and timestamps
sudo cp -a /etc/hostname /etc/hostname.bak
# Edit the configuration file
sudo nano /etc/hostname
Software download and update¶
On Debian, software is typically installed using APT or dpkg. Understanding their respective roles helps distinguish between installing packages from repositories and manually installing local .deb packages.
This section introduces the basic methods for installing and updating software on Debian, so that users can understand commands such as apt install when setting up their development environment.
For details about APT, common commands, and repository configuration, see Software update.
Overview of APT and dpkg¶
In Debian systems, software installation mainly relies on the following two types of tools:
Tools |
Function |
Typical scenario |
|---|---|---|
APT |
Find and download software from software sources and automatically handle dependencies |
Install software and update system online. |
dpkg |
Install local .deb package directly |
Manually install the installation package provided by the manufacturer. |
APT is a high-level package management tool that retrieves packages from repositories and resolves dependencies automatically. dpkg is a low-level tool used to install local .deb packages and does not resolve dependencies automatically.
Common APT commands¶
apt update¶
Update the package list. This command is used to refresh the local package index. This command does not install or upgrade any software, it is only used to update information about available software packages and their latest versions in the software repository.
Run the apt update command before installing software or upgrading the system.
sudo apt update
apt upgrade¶
Upgrade installed software packages. This command will upgrade all installed software packages on the system to the latest version available in the software repository.
sudo apt upgrade
The usual procedure is to run update first, followed by upgrade.
apt install¶
The apt install command is the most commonly used command for installing packages. It retrieves the specified package from the configured repositories, downloads and installs it, and automatically resolves its dependencies at the same time.
sudo apt install <package_name>
When setting up a development environment, you will often use commands such as the following:
# Install Python 3
sudo apt install -y python3
# Install Git
sudo apt install -y git
# Install the Vim editor
sudo apt install -y vim
# Or
# Install multiple packages at once
sudo apt install -y python3 git vim
apt remove¶
The apt remove command removes the specified package from the system.
# Basic uninstall: Removes the package while preserving existing configuration files (useful if reinstalling later)
sudo apt remove -y <package_name>
# Purge: Removes both the package and all global configuration files under /etc/
sudo apt purge -y <package_name>
# Remove orphaned dependencies: Automatically scans and removes unused dependencies left behind by uninstalled packages
sudo apt autoremove --purge -y
# Clean local package cache: Clears downloaded .deb package archives in /var/cache/apt/archives/ to free up disk space
sudo apt clean