Why you can't avoid it
A server has no windows and no mouse. There's only a text prompt.
Besides, many developer tools are driven only from there: version control, package installation, builds, running tests. Someone afraid of the terminal spends several times longer on simple things.
The good news: twenty commands cover ninety per cent of tasks.
Moving around and looking
pwd where am I
ls what's here
ls -la in detail, including hidden files
cd folder go into it
cd .. up one level
cd ~ home
Files and folders
mkdir name create a folder
mkdir -p a/b/c create nested folders at once
touch file create an empty file
cp what where copy
cp -r folder where copy a folder entirely
mv what where move or rename
rm file delete
rm -r folder delete a folder
About deletion: the command asks no confirmation and uses no wastebasket. What's deleted is gone. Before pressing enter on a delete with a wildcard, look with your eyes at exactly what you're deleting.
Viewing contents
cat file show it all
head -20 file first 20 lines
tail -20 file last 20 lines
tail -f file follow as it's written
less file page through (q to quit)
Following a file as it's written is the main tool when investigating a running server.
Searching
grep "text" file find lines containing text
grep -r "text" . search every file in a folder
grep -i "text" file case-insensitive
find . -name "*.py" find files by name
Searching file contents is a daily activity. Learn it properly.
Processes and the system
ps aux | grep python which processes are running
kill number stop a process
df -h disk space
du -sh folder how much a folder occupies
top what's loading the system
Checking disk space saves you regularly: a disk filled by logs is a classic cause of sudden failure.
Chaining commands
The terminal's main strength is passing one command's output into another:
cat app.log | grep ERROR | tail -20
Read as: take the file, keep the error lines, show the last twenty.
Redirecting into a file:
command > file write, overwriting
command >> file append
Time-saving habits
The completion key. Start typing a filename and press it — it completes. Not a luxury but a way to avoid mistyping paths.
The up arrow. Previous commands. Don't retype.
History search. The reverse-search shortcut finds a command you typed a week ago.
Interrupt. The shortcut that stops the current command is the first thing to memorise, so you aren't afraid to run anything.
What not to do
Don't run commands from the internet without understanding them. Especially with elevated privileges. A line that downloads a script and immediately runs it as administrator is the standard way to hand your machine to someone else.
Don't delete recursively from the root. The classic catastrophe. Always check where you are before deleting.
Don't work as administrator all the time. Elevate only where it's genuinely needed.
Хватит читать — пора делать
На CohortX можно найти команду под пет-проект и получить тот самый опыт, о котором спрашивают на собеседовании.
Похожие статьи
- Терминал для новичка: команды на каждый деньПочему без него не обойтись, двадцать команд, которых хватает на всё, и приёмы, экономящие время.