Ravindra BagaleCourses & study guides

5. Linux Basic Commands

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

Vim madhe adaklyavar khup students terminal band kartat. Ghabru naka: Esc don vela, mag :q! aani Enter. Aani config edit karnyapurvi nehmi backup ghya: 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: /etc config, /var/log logs, /home users, /tmp world-writable, /var/www websites.
  • Navigate with pwd, ls -la, cd; files with mkdir -p, cp -r, mv, rm (permanent!).
  • View with less, head, tail -f.
  • Permissions r=4, w=2, x=1: 755 folders, 644 files, 400 keys; never 777. 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.