Linux Operations from Scratch: 30 Essential Commands for Beginners
Designed for newcomers, this tutorial introduces 30 fundamental Linux commands spanning file navigation, creation, copying, permissions, user switching, disk and memory inspection, process management, log searching, archiving, and safe service deployment, complete with practical examples and critical safety warnings.
What Is Linux and Why Learn It?
Linux is an open-source Unix-like operating system whose kernel was first released by Linus Torvalds in 1991. It follows the POSIX standard, supports multi-user, multi-tasking, and multi-threading, and offers high stability and security, making it widely used in servers, embedded systems, and development environments.
Linux Filesystem Structure
The Linux filesystem adopts a tree structure where all files and directories are mounted from the root directory (/), and devices are also managed as files.
File Management
Navigation Commands
Core navigation commands include:
pwd # Show current directory (Where am I?)
ls -l # Detailed listing
ls -a # Show hidden files
cd /home # Go to home directory
cd .. # Go up one level
cd ../.. # Go up two levels
cd . # Current directory (rarely used alone)
cd ~ # Go to current user's home directory
/ # Root directory
~ # Shortcut for current user's home directoryMemory aid: pwd = where am I, ls = what's here, cd = where to go.
File Operations
Common file operations:
# Commands without a path operate in the current directory
# Example: mkdir xxx creates directory xxx in current directory
# Example: cp filename backup/ copies file to backup directory
# Create
mkdir dirname # Create directory
mkdir fileName.txt # Create file (touch works similarly)
# Copy and move
cp file.txt backup/ # Backup file
cp -a # Recursively copy files and directories
mv old.txt new.txt # Rename
mv file.txt /tmp/ # Move file
# View content
cat file.txt # Display entire file at once
more file.txt # Page-by-page view (space to scroll)
tail -f log.txt # Real-time log monitoring (ops essential!)
# Edit with vi/vim
vi # Basic editor; creates file if missing
vim # Enhanced version; both create file if missing
vi/vim fileName # Enter command mode
Press i to enter insert mode
Save: Press Esc, then :w # w = write
Exit: :q # q = quit
Save and exit: :wq
Discard changes and exit: :q!Dangerous Commands
rm file.txt # Delete file.txt
rm -r folder/ # Delete directory recursively (careful!)
rm -rf / # DESTRUCTIVE! NEVER RUN!
# Options explained:
-r Recursive deletion for directories and contents
-i Interactive mode, prompts before each deletion
-d Handle empty directories
-f Force deletion, ignore non-existent files, no confirmationHard-earned lesson: Never use rm -rf lightly; "deleting the database and fleeing" is no joke.
Permission Management (Security Foundation)
Understanding Permissions
rwx r-x r-x
| | └── Others: read and execute
| └───── Group: read and execute
└──────── Owner: read, write, execute
Numeric mode uses three octal digits (user, group, others). Each digit is the sum of:
4 = read (r)
2 = write (w)
1 = execute (x) 7= 4+2+1 = read, write, execute 6 = 4+2 = read, write 5 = 4+1 = read, execute
Changing Permissions
# Symbolic mode (intuitive)
chmod u+x script.sh # Add execute permission for owner
chmod o-w file.txt # Remove write permission for others
# Numeric mode (efficient)
chmod 755 script.sh # Owner full, others read/execute
chmod 644 config.txt # Owner read/write, others read-only
chmod 777 script.sh # All permissions for all (use cautiously)
chmod 644 file.txt # Owner read/write, others read-only
# Options
chmod -R # Recursively change directory and contents
chmod -v # Verbose output showing changesUser Switching
# After each command you'll be prompted for password (input is hidden)
su # Switch to another user (default root)
su - # Load target user's environment (e.g., /root/.bashrc)
su - username # Switch to specific user with environment
su username # Switch without loading environment
sudo # Execute command as another user
sudo -i # Switch to root user (equivalent to sudo su)
sudo -u username command # Run command as specific userSystem Management (Daily Operations)
Disk and Memory Inspection
# Disk space
df
df -h # Human-readable format
df -T # Show filesystem type
# Memory usage
free
free -h # Human-readable format
# Directory/file size
du
du -sh # Show directory size in human-readable format
# Real-time process and resource view
topProcess Management
# View processes
ps
ps aux # All processes
-e or -a # Show all processes
-f # Full format with command line arguments (combine with -e)
ps -ef # All processes with full details
-u # Processes for specific user
-p # Process by specific PID
# Terminate processes
kill # Graceful termination
kill -9 PID # Force kill (use sparingly)
kill -s PID # Request normal terminationFile Search and Archiving
# Find files in directory tree
find
find /home -name "*.txt"
# Search text patterns in files
grep
grep "error" logfile # Find lines containing "error"
# Archive and compress (commonly with gzip/bzip2)
# tar -czvf archive.tar.gz folder (compress)
-c Create archive
-z Use gzip compression
-v Verbose output
-f archive.tar.gz Output filename
# tar -xzvf archive.tar.gz (extract)
-x Extract archive
-z Handle gzip compression
-v Verbose output
-f archive.tar.gz Input filenamePractical Applications (Solving Real Problems)
Starting and Stopping Programs
# Basic: program exits when terminal closes
java -jar app.jar
# Advanced: runs after terminal closes with &
java -jar app.jar &
# Professional: with logging and process monitoring
nohup java -jar xxx.jar > /path/to/output.log 2>&1 &
# Breakdown:
nohup # Ignore SIGHUP, keep running after terminal closes
java -jar xxx.jar # Start Java application
> # Redirect stdout to file
/path/to/output.log # Custom log file path
2>&1 # Merge stderr into stdout (both go to output.log)
& # Run in background
# Find and stop a Java program
ps -ef | grep java
kill pidLog Analysis
# Find error logs
grep "ERROR" app.log
# Real-time monitoring with keyword filter
tail -f app.log | grep "important keyword"
# Count access lines
cat access.log | wc -l
# Find and delete log files older than 30 days (with confirmation per file)
find /var/log -name "*.log" -mtime +30 -exec rm -i {} \;
# Alternative using -ok for confirmation
find /var/log -name "*.log" -mtime +30 -ok rm {} \;Learning Advice
Back up before operating – Good use of cp prevents system crashes and data loss.
Use tab completion heavily – Reduces typing errors.
Learn and understand continuously – Growth comes from hands-on work.
Never joke in production – Production is the lifeline of your system; a mistake can bring everything down.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Engineer Tang's Implementation Study Notes
Old Tang | Pseudo-full-stack tech player: writes code without going bald, manages projects without going crazy, delivers without staying up late. No formal tutorials here, only a "slacking-off" practical manual that cures system pain points. Focuses on Shell, SQL, Java, and delivery, turning complexity into simplicity and making efficiency fun.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
