Thursday, May 1, 2025

vi commands

Here is the complete **HTML version** of the `vi` commands guide with examples: ```html vi Editor Commands and Examples

๐Ÿ“ vi Editor Commands with Examples

๐Ÿ”น Starting vi

vi filename

This opens filename in vi. If it doesn't exist, vi will create it when saved.

๐Ÿ“– Modes in vi

  • Normal Mode: Default mode for navigation and commands.
  • Insert Mode: For editing text.
  • Command Mode: For file operations (triggered by :).

✍️ Insert Mode Commands

CommandDescription
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oOpen new line below
OOpen new line above
EscExit insert mode

๐Ÿงช Example:

Press i → type your text → press Esc to exit insert mode.

๐Ÿ“‚ File Commands (Command Mode)

CommandDescription
:wSave the file
:qQuit vi
:wqSave and quit
:q!Quit without saving
:w new.txtSave content to new.txt

๐Ÿ” Navigation Commands

CommandDescription
hMove left
lMove right
jMove down
kMove up
0Beginning of line
$End of line
GEnd of file
ggStart of file
:nGo to line number n
Ctrl+dScroll down half page
Ctrl+uScroll up half page

✂️ Editing Commands

CommandDescription
xDelete character under cursor
ddDelete current line
yyCopy (yank) current line
pPaste below
PPaste above
uUndo last change
Ctrl+rRedo
r<char>Replace character under cursor
REnter replace mode

๐Ÿ” Search and Replace

CommandDescription
/wordSearch forward for "word"
?wordSearch backward for "word"
nRepeat last search
:%s/old/new/gReplace all "old" with "new"
:5,10s/foo/bar/gReplace from line 5 to 10

✅ Practical Example

$ vi demo.txt

Then inside vi:

  1. Press i and type:
  2. Hello World
    This is a test file.
  3. Press Esc
  4. Type :wq to save and quit
``` You can save this as `vi-commands.html` and open it in any browser. Would you like a downloadable file version or additional content like visual cheat sheets or keyboard diagrams?

jobs command

Here is the combined HTML version of both responses: the explanation of the `jobs` command and the step-by-step example. ```html Unix jobs Command - Guide and Example

Unix jobs Command - Usage Guide

๐Ÿ”ง What Is a "Job" in Unix?

A job refers to a command or process started from a shell. Jobs can be:

  • Foreground: Active and attached to the terminal.
  • Background: Running behind the scenes.
  • Stopped: Suspended with Ctrl+Z.

๐Ÿ“˜ Usage of jobs Command

jobs

This displays all jobs started from the current shell, including their ID, state, and command.

๐Ÿ“‹ Example Output

$ sleep 100 &
[1] 12345
$ jobs
[1]+  Running                 sleep 100 &

⌨️ Related Job Control Commands

CommandDescription
&Run a command in the background
Ctrl+ZPause (suspend) a foreground job
fgResume job in foreground
bgResume job in background
kill %1Kill job with ID 1
jobs -lShow job PID
jobs -pShow job all processes

✅ When It's Useful

  • Managing long-running processes during an active shell session
  • Suspending/resuming tasks without killing them
  • Debugging shell-based automation or accidental background tasks

๐Ÿงช Step-by-Step Example: Managing Jobs

๐Ÿ”น Step 1: Start a Long-Running Command

$ sleep 300

๐Ÿ”น Step 2: Suspend with Ctrl + Z

^Z
[1]+  Stopped                 sleep 300

๐Ÿ”น Step 3: Check Jobs

$ jobs
[1]+  Stopped                 sleep 300

๐Ÿ”น Step 4: Resume in Background

$ bg %1
[1]+ sleep 300 &

๐Ÿ”น Step 5: Bring Back to Foreground

$ fg %1
sleep 300

๐Ÿ”น Step 6: Kill the Job

$ jobs
[1]+  Running                 sleep 300 &

$ kill %1

$ jobs
[1]+  Terminated              sleep 300

✅ Summary

  • & to run in background
  • Ctrl+Z to pause
  • bg / fg to resume
  • kill to terminate
``` You can save this as `jobs-command.html` and open it in any web browser. Want me to include downloadable links or CSS framework enhancements?

Unix Top Command

Here's the above explanation in clean, semantic HTML format: ```html Unix top Command - Usage Guide

Unix top Command - Usage Guide

๐Ÿ” What top Shows

When you run top, it displays:

1. System Summary

  • uptime: How long the system has been running.
  • users: Number of logged-in users.
  • load average: 1, 5, and 15 minute load.
  • Tasks: Total, running, sleeping processes, etc.
  • CPU usage:
    • %us: user processes
    • %sy: system/kernel processes
    • %id: idle time
    • %wa: I/O wait
    • %hi: hardware interrupts
    • %si: software interrupts
    • %st: steal time (VMs)
  • Memory and Swap: Total, used, free, buffers, etc.

2. Process List

Displays information per process:

  • PID: Process ID
  • USER: Owner
  • %CPU: CPU usage
  • %MEM: Memory usage
  • TIME+: Total CPU time used
  • COMMAND: Command name

๐Ÿ› ️ Common Day-to-Day Usage in Production

  • Find High CPU Usage: Use P to sort by CPU usage.
  • Check Memory Leaks: Use M to sort by memory usage.
  • Identify Stuck or Zombie Processes: Look for state Z.
  • Check Load Averages: High load may indicate system stress.
  • Check I/O Wait: High %wa indicates disk bottlenecks.
  • Kill a Misbehaving Process: Use k and enter PID.

๐Ÿง  Useful Keybindings in top

Key Action
PSort by CPU usage
MSort by memory usage
kKill a process (enter PID)
RRenice a process
cToggle full command display
1Show all CPU cores
hHelp
qQuit

๐Ÿงช Pro Tips

  • Use top -u <username> to filter by user.
  • Use top -p <PID> to monitor a specific process.
  • Use htop for a more visual alternative (if installed).
``` You can save this as an `.html` file and open it in any browser. Want me to include a live example or a downloadable template?

Sudo Command Details

sudo -l -U a762311 Output : User a762311 may run the following commands on MACLB390804