twinlakestech.com

Debian Linux Terminal Cheat Sheet

System

System Information

Display all system information. uname -a

Show current hostname and related details. hostnamectl or cat /etc/*-release

List CPU architecture information. lscpu

List disk information. lsblk

List USB information. (may need usbutils installed) lsusb

List PCI information. (may need pciutils installed) lspci

Show system time. timedatectl status

System Monitoring and Management

Display real-time system processes. top

An interactive process viewer (needs installation). htop

Show disk usage in a human-readable format. df -h

Display free and used memory in MB. free -m

Terminate a process. kill <process id>

Running Commands

Run a command in the background. <command> &

Display background commands. jobs

Bring command to the foreground. fg <command number>

Service Management

Start a service. sudo systemctl start <service>

Stop a service. sudo systemctl stop <service>

Check the status of a service. sudo systemctl status <service>

Reload a service’s configuration without interrupting its operation. sudo systemctl reload <service>

Follow the journal, showing new log messages in real time. journalctl -f

Display logs for a specific systemd unit. journalctl -u <unit_name>

Cron Jobs and Scheduling

Edit cron jobs for the current user. crontab -e

List cron jobs for the current user. crontab -l

Files

File Management

List files and directories. ls

Create an empty file or updates the last accessed date. touch <filename>

Copy files from source to destination. cp <source> <destination>

Move files or rename them. mv <source> <destination>

Delete a file. rm <filename>

Directory Navigation

Display the current directory path. pwd

Change the current directory. cd <directory>

Create a new directory. mkdir <dirname>

File Permissions and Ownership

Change file permissions. chmod [who][+/-][permissions] <file>

Make a file executable by its owner. chmod u+x <file>

Change file owner and group. chown [user]:[group] <file>

Searching and Finding

Find files and directories. find [directory] -name <search_pattern>

Search for a pattern in files. grep <search_pattern> <file>

Archiving and Compression

Compress files into a tar.gz archive. tar -czvf <name.tar.gz> [files]

Extract a compressed tar archive. tar -xvf <name.tar.[gz|bz|xz]> [destination]

Text Editing and Processing

Open a file in the Nano text editor. nano <file>

Display the contents of a file. cat <file>

Display the paginated content of a file. less <file>

Show the first few lines of a file. head <file>

Show the last few lines of a file. tail <file>

Print every line in a file. awk '{print}' <file>

Packages

Package Management

Install a package. sudo apt install <package>

Reinstall a broken package. sudo apt install -f --reinstall <package>

Search for APT packages. apt search <package>

List available package versions. apt-cache policy <package>

Update package lists. sudo apt update

Upgrade all upgradable packages. sudo apt upgrade

Remove a package. sudo apt remove <package>

Remove a package and all its configuration files. sudo apt purge <package>

Users and Groups

User Management

Show which users are logged in. w

Create a new user. sudo adduser <username>

Delete a user. sudo deluser <username>

Set or change the password for a user. sudo passwd <username>

Switch user. su <username>

Lock a user account. sudo passwd -l <username>

Unlock a user password. sudo passwd -u <username>

Set user password expiration date. sudo chage <username>

Group Management

Display user and group IDs. id [username]

Show the groups a user belongs to. groups [username]

Create a new group. sudo addgroup <groupname>

Delete a group. sudo delgroup <groupname>

Add a user to a group. sudo usermod -a -G [groupname] [username]

Networking

Networking

Display network interfaces and IP addresses. ip addr show

Show network statistics. ip -s link

Show listening sockets. ss -l

Ping a host and outputs results. ping <host>

Show DNS configuration. cat /etc/resolv.conf

Firewall Management

Display the status of the firewall. sudo ufw status

Enable the firewall. sudo ufw enable

Disable the firewall. sudo ufw disable

Allow traffic on a specific port or service. sudo ufw allow <port/service>

Deny traffic on a specific port or service. sudo ufw deny <port/service>

Delete an existing rule. sudo ufw delete allow/deny <port/service>

SSH and Remote Access

Connect to a remote host via SSH. ssh <user@host>

Securely copy files between hosts. scp <source> <user@host>:<destination>