5.9 Getting Help and Editing Files (nano, vim)
man ls # full manual page (q to quit, /word to search)
ls --help # short usage summary
whatis chmod # one-line description
apropos network # search manual pages by keyword
type cd # is it a built-in, alias or program?
which nginx # full path of a command
Text editors: nano and vim
nano — easiest for beginners
sudo nano /etc/nginx/nginx.conf
Shortcuts are shown at the bottom (^ means Ctrl): Ctrl+O then Enter = save, Ctrl+X = exit, Ctrl+W = search, Ctrl+K = cut line, Ctrl+U = paste.
vim — available everywhere
Vim has modes: Normal (for commands, the default), Insert (for typing) and Command-line (after :).
| Keys | Action |
|---|---|
i |
Enter insert mode (start typing) |
Esc |
Back to normal mode |
:w |
Save |
:q |
Quit (:q! quit without saving) |
:wq or ZZ |
Save and quit |
dd / yy / p |
Delete (cut) line / copy line / paste |
u / Ctrl+R |
Undo / redo |
/text then n |
Search forward, next match |
:set number |
Show line numbers |
gg / G |
Go to first / last line |
:%s/old/new/g |
Replace all |
Stuck in vim?
Press Esc two times, then type :q! and press Enter. You are out without saving.
Ravindra Bagale's Tip
When stuck in Vim, many students close the terminal. Don't worry: press Esc twice, then :q! and Enter. And always take a backup before editing a config: sudo cp file file.bak.
Ravindra Bagale's Tip – मराठी
Vim मध्ये अडकल्यावर बरेच students terminal बंद करतात. घाबरू नका: Esc दोन वेळा, मग :q! आणि Enter. आणि config edit करण्यापूर्वी नेहमी backup घ्या: sudo cp file file.bak.
Ravindra Bagale's Tip – हिंदी
Vim में अटकने पर बहुत से students terminal बंद कर देते हैं. घबराओ मत: Esc दो बार, फिर :q! और Enter. और config edit करने से पहले हमेशा backup लो: sudo cp file file.bak.
Practice task
Open ~/notes.txt in vim, write three lines, save and quit. Open the same file in nano, add a line, save with Ctrl+O and exit with Ctrl+X. Use man chmod to find what the -R option does.
Thodkyaat sangaycha tar
- Map:
/etcconfig,/var/loglogs,/homeusers,/tmpworld-writable,/var/wwwwebsites. - Navigate with
pwd,ls -la,cd; files withmkdir -p,cp -r,mv,rm(permanent!). - View with
less,head,tail -f. - Permissions r=4, w=2, x=1:
755folders,644files,400keys; never777. SUID programs are privesc targets. - Users:
useradd -m,passwd,usermod -aG,sudo -l. - Packages:
yum(Amazon Linux/CentOS),apt(Ubuntu). Processes:ps,top,kill.
Samjla ka? Nasel tar permissions cha table punha vacha aani terminal var try kara. Aata pudhe jaauya advanced commands kade.