Overview
1. File Operations (Basic commands you'll use daily)ls: View files/folders in the current directory
Common flags: ls -l shows detailed info (permissions, size, modification time), ls -a shows hidden files (including those starting with .). These two are enough to get by.
cp: Copy files/folders
For files: cp source target, e.g., cp test.txt /home. For folders, you need to add -r, otherwise it'll throw an error, e.g., cp -r docs /backup — you'll remember this after making the mistake once.
mv: Move files/folders, also rename
Move: mv filename target_dir, e.g., mv photo.jpg ~/Pictures. Rename is even simpler: mv oldname.txt newname.txt — no extra command needed.
rm: Delete files/folders
Delete a file with rm filename. To delete a folder, you must add -r (recursive), e.g., rm -r tempdir. Important warning: never run rm -rf * carelessly, especially as root — there's no undo. If you're unsure, cd to another directory first.
2. Directory Navigation (switching, creating, checking paths)
cd: Change directory — the most used command
Go home: cd ~ (no matter where you are, this takes you back). Go up one level: cd .. (two dots, shorthand for "one level up"). Go to root: cd /. Also, cd - returns to the previous directory — handy for switching back and forth.
mkdir: Create folders
Basic: mkdir folder_name. To create nested directories (e.g., a/b/c), use mkdir -p a/b/c — no need to create one level at a time.
pwd: Print the full current path
Sometimes after cd-ing around, you forget where you are. Just type pwd and it shows the full path, e.g., /home/user/docs — keeps you oriented.
3. System Status Checks (for troubleshooting)
ps: View running processes
No need to remember complex flags — ps -ef shows detailed info for all processes. You can also pipe to grep for filtering, e.g., ps -ef | grep firefox to see only Firefox-related processes.
top: View real-time system resource usage
Typing top brings up a dynamic interface showing CPU and memory usage, plus the top resource-consuming processes. Press q to exit.
df: View disk space usage
df -h shows sizes in human-readable units (GB/MB). For example, you can see how much space is left on the root partition. Without -h, it shows bytes, which is harder to read — so always include -h.
4. Permission Management (good enough for beginners)
chmod: Change file/folder permissions
The most common is numeric permissions: e.g., chmod 755 filename. Simple logic: 7 = read + write + execute (rwx), 5 = read + execute (rx). So 755 means you can read/write/execute, while others can only read and run — good for scripts. For regular documents, chmod 644 is fine (6 = read + write). No need to overthink — these two numbers are enough for most cases.
sudo: Temporarily get admin privileges
Some operations require root permissions (e.g., system config changes or installing software). Just prefix with sudo, e.g., sudo apt install package_name (Ubuntu-based) or sudo yum install package_name (CentOS-based). Enter your own user password — no need to switch to root permanently.
5. Other Useful Commands
cat: View file contents
Good for small files: cat filename shows everything at once. For example, cat /etc/hosts to check the hosts file. If the file is too large, use less filename for paged viewing — arrow keys to scroll, q to quit.
grep: Search text content
For example, grep "error" app.log finds "error" in a log file, helping you quickly locate issues. Add -i to ignore case: grep -i "Error" app.log — useful when case sensitivity varies.
ping: Test network connectivity
To check if you can reach a server, ping domain/IP, e.g., ping baike300.com. It shows latency and packet loss. Press Ctrl+C to stop.
