Passion's Log

Where code meets life

← Back to blog

Part 3 - Summary of Common Linux Commands (Ubuntu)

Linux is the foundational OS for operations, development, cloud, containers, automation, and AI engineering. This article summarizes common and practical Linux commands for Ubuntu users.

Linux #Linux#System Administration#Troubleshooting

Preface

Linux is the foundational operating system for operations, development, cloud computing, containers, automation, and AI engineering practices. For users working with Ubuntu, mastering common commands is essential for daily operations, system administration, and troubleshooting;

This article compiles a summary of common and practical Linux commands, suitable for daily learning and reference.


Commands

Directory and File Operations

View current directory

pwd

View files in directory

ls

View detailed information

ls -l

Show hidden files

ls -la

Change directory

cd /etc
cd ..
cd ~

Create directory

mkdir test
mkdir -p /data/test/logs

Create empty file

touch test.txt

Copy file

cp a.txt b.txt

Copy directory

cp -r dir1 dir2

Move/Rename file

mv old.txt new.txt
mv file.txt /tmp/

Delete file

rm file.txt

Delete directory

rm -r testdir

Force delete

rm -rf testdir

File Viewing Commands

View file content

cat file.txt

View with pagination

less file.txt

View first 10 lines

head file.txt

View first 20 lines

head -n 20 file.txt

View last 10 lines

tail file.txt

View logs in real-time

tail -f /var/log/syslog

File Search and Find

Find file

find / -name nginx.conf

Find txt files in current directory

find . -name "*.txt"

Find directory

find /data -type d -name logs

Find command path

which python3
which docker

Search keyword in file

grep "error" app.log

Case-insensitive search

grep -i "error" app.log

Show line numbers

grep -n "error" app.log

Recursive search in directory

grep -rn "listen" /etc/nginx/

User and Permission Management

View current user

whoami

View logged-in users

who

Switch user

su - root

Execute command with sudo

sudo apt update

Change file permissions

chmod 644 file.txt
chmod 755 script.sh

Change file owner

chown user:user file.txt

Recursively change directory permissions

chmod -R 755 /data/test

Recursively change owner

chown -R ubuntu:ubuntu /data/test

System Information View

View system version

cat /etc/os-release

View kernel version

uname -r

View hostname

hostname

View CPU information

lscpu

View memory information

free -h

View disk usage

df -h

View directory size

du -sh /data

View block devices

lsblk

Process Management

View current processes

ps -ef

Find specific process

ps -ef | grep nginx

View processes dynamically

top

More friendly process view tool

htop

Kill process

kill 1234

Force kill process

kill -9 1234

Kill process by name

pkill nginx

View IP address

ip a

View routing table

ip route

Test network connectivity

ping 8.8.8.8

Test domain resolution

ping www.baidu.com

View port listening

ss -tunlp

View specific port

ss -tunlp | grep 80

View network connections

netstat -tunlp

Test port connectivity

telnet 192.168.1.10 22

Test HTTP service with curl

curl http://127.0.0.1
curl -I http://127.0.0.1

Download file

wget https://example.com/file.tar.gz

Package Management (Ubuntu)

Update package source

sudo apt update

Upgrade packages

sudo apt upgrade -y

Install software

sudo apt install nginx -y

Uninstall software

sudo apt remove nginx -y

Complete uninstall

sudo apt purge nginx -y

Auto clean unused packages

sudo apt autoremove -y

Search package

apt search docker

Service Management (systemd)

View service status

systemctl status nginx

Start service

sudo systemctl start nginx

Stop service

sudo systemctl stop nginx

Restart service

sudo systemctl restart nginx

Reload configuration

sudo systemctl reload nginx

Set auto-start on boot

sudo systemctl enable nginx

Disable auto-start on boot

sudo systemctl disable nginx

View boot logs

journalctl -b

View specific service logs

journalctl -u nginx -f

Compression and Decompression

Pack as tar

tar -cvf archive.tar test/

Unpack tar

tar -xvf archive.tar

Pack and compress as tar.gz

tar -zcvf archive.tar.gz test/

Decompress tar.gz

tar -zxvf archive.tar.gz

Compress zip

zip -r test.zip test/

Decompress zip

unzip test.zip

Disk and Mounting

View disk partitions

fdisk -l

View file system usage

df -h

Mount disk

mount /dev/sdb1 /mnt

Unmount disk

umount /mnt

View UUID

blkid

Edit file with vim

vim test.txt

Edit file with nano

nano test.txt

User Management

Create user

sudo useradd -m testuser

Set password

sudo passwd testuser

Delete user

sudo userdel -r testuser

View user information

id testuser

SSH Remote Connection

Remote login

ssh user@192.168.1.100

Connect with specific port

ssh -p 2222 user@192.168.1.100

Copy file to remote server

scp file.txt user@192.168.1.100:/tmp/

Copy file from remote server to local

scp user@192.168.1.100:/tmp/file.txt ./

Common Log Paths (Ubuntu)

System logs

/var/log/syslog

Authentication logs

/var/log/auth.log

Kernel logs

/var/log/kern.log

DPKG installation logs

/var/log/dpkg.log

View log example

tail -f /var/log/syslog
tail -f /var/log/auth.log

Common Combined Commands

Find who occupies a specific port

ss -tunlp | grep 8080

Find a specific process

ps -ef | grep python

View large files/directories

du -sh * | sort -hr

View recently modified files

ls -lt

Run program in background

nohup python3 app.py > app.log 2>&1 &

View background jobs

jobs

Linux Learning Suggestions

For Ubuntu beginners, there is no need to memorize all commands at once. It is more important to understand several core directions:

  • How to operate files and directories
  • How to manage services
  • How to view processes
  • How to troubleshoot network issues
  • How to view logs
  • How to install software
  • How to handle permissions

Once these high-frequency commands are mastered, whether doing Linux operations, Docker, Kubernetes, or AI development and service deployment, it will be much easier.


Comments

Back to top