如何學習 Linux 命令列,並記住真正需要的指令
How to Learn the Linux Command Line (and Remember the Commands You Actually Need)
學習 Linux 命令列應先熟習目錄操作、讀取檔案、管道、grep、find,以及基本權限和程序管理,再透過日常實際操作加深記憶。作者建議把查過多次的指令記錄下來,並定期重看。Recl 可整理影片、播客及文章的重點,按間隔重温安排再次複習。
I used Linux servers for about two years before I could do anything on one without a browser tab open. Every task started the same way: search "how to find a file linux", copy the first find command on Stack Overflow, paste it, hope. I'd done that exact search maybe forty times. It never stuck, because I never had to think about it.
What finally worked was boring. I picked a small set of commands, learned what each one actually does, and kept using the terminal for things I'd normally click through. Here's the order I'd do it in again.
Learn to move around first
Everything else depends on knowing where you are. Spend one evening on just these:
pwd
ls -la
cd ~/projects
cd -
cd ..
cd - jumps back to the last directory you were in, which I didn't learn for an embarrassingly long time. ls -la shows hidden files and permissions. That's enough to stop feeling lost.
Then learn tab completion properly. Press Tab once to complete, twice to see the options. Half of my early typos came from typing full paths by hand.
Read files before you edit them
Before reaching for an editor, get comfortable looking at things:
cat config.yml
less /var/log/syslog
head -n 20 access.log
tail -f app.log
less is the one to really learn. Inside it, /word searches, n jumps to the next match, G goes to the end and q quits. The same keys show up in man pages, so you get two tools for the price of one.
tail -f follows a log as it's written. The first time I watched a request hit my app live in a terminal, debugging stopped feeling like guesswork.
Understand pipes, then grep
Most "Linux magic" you see online is small commands glued together with |. Each command takes text in and sends text out. Once that clicks, long one-liners stop looking like spells.
cat access.log | grep " 500 " | wc -l
history | grep docker
ps aux | grep node
grep is the command I use more than any other. Learn three flags and you're covered for most days: -i for case-insensitive, -r to search a folder recursively, -n to show line numbers. grep -rn "TODO" src/ beats any IDE search I've used for quick checks.
Find things without searching the web
This was my forty-searches command. The shape is find <where> <what>:
find . -name "*.env"
find /var/log -mtime -1
find . -type d -name node_modules
I stopped forgetting it once I noticed the pattern: start location first, then tests. Reading it out loud ("find, starting here, things named star dot env") helped more than any cheat sheet.
Permissions and processes, just enough
You'll hit Permission denied eventually. Learn what ls -l is telling you: rwx for the owner, the group and everyone else. chmod +x script.sh makes a script runnable, and chown changes who owns a file. Don't chmod 777 your way out of problems; it's the Linux version of turning it off and on again, except it leaves the door open.
For processes, ps aux, top (or htop if it's installed) and kill <pid> cover most of it. lsof -i :3000 tells you what's hogging a port, which saves me at least once a month.
Practice on real tasks
Reading a list of 100 commands won't make them stick. Using ten of them every day will. A few habits that helped me:
- Rename and move files from the terminal instead of the file manager for a week.
- When you look something up, type it out instead of pasting it.
- Run
man <command>before searching the web. Most man pages have an EXAMPLES section near the bottom. - Keep a plain text file of commands you had to look up twice.
That last one matters more than it sounds. If you needed something twice, you'll need it a third time.
Make the learning stick
My problem was never finding good explanations. There are great ones, like the free Linux Journey site, Julia Evans' zines, and plenty of short YouTube videos on things like awk or xargs. The problem was that I'd watch a ten-minute video on a Sunday, feel smart, and have none of it left by the time I actually needed it a month later.
That gap is the reason I built Recl. You share a video, reel, podcast or article to it, it summarizes the key points, files it under a topic like "Linux", and brings it back on a spaced repetition schedule so you review it before you forget it. If you'd rather keep it simple, a notes file you reread every week or two does a lot of the same job. The point is to see the material again before it's gone, whatever you use.
What I'd skip at first
Shell scripting, awk, sed and writing your own aliases are all worth it later. Early on they're a distraction. I tried to learn awk in my first month and spent an afternoon on syntax I didn't use again for a year. Get fluent with moving around, reading files, piping and finding things. Everything else builds on those, and it's much easier to learn once the basics don't need any thought.
If you want a starting point for this week, open a terminal and do one real task you'd normally do with your mouse. Then do another tomorrow.
I build Recl, an AI learning app that saves your videos, reels, podcasts and articles, summarizes them, sorts them into topics, and uses spaced repetition so you remember what you learned.
來源:DEV Community · dev.to