Command Line Reference Guide

Bash Command Reference

File Operations

  • touch: Create an empty file
    • Usage: touch [filename]
  • cp: Copy files and directories
    • Usage: cp [options] [source] [destination]
  • mv: Move or rename files and directories
    • Usage: mv [options] [source] [destination]
  • rm: Remove files and directories
    • Usage: rm [options] [file/directory]

File Viewing and Editing

  • cat: Concatenate and display file content
    • Usage: cat [filename]
  • less: Display file content one page at a time
    • Usage: less [filename]
  • head: Display the beginning of a file
    • Usage: head [options] [filename]
  • tail: Display the end of a file
    • Usage: tail [options] [filename]
  • nano: Text editor
    • Usage: nano [filename]

File Permission Management

  • chmod: Change file permissions
    • Usage: chmod [options] [mode] [filename]
  • chown: Change file owner and group
    • Usage: chown [options] [owner:group] [filename]

Process Management

  • ps: Display information about processes
    • Usage: ps [options]
  • kill: Terminate processes
    • Usage: kill [options] [process_id]

System Information

  • uname: Print system information
    • Usage: uname [options]

Miscellaneous

  • echo: Display text
    • Usage: echo [text]
  • grep: Search for patterns in files
    • Usage: grep [options] [pattern] [file]
  • find: Search for files and directories
    • Usage: find [options] [path] [expression]

Help

  • man: Display manual pages for commands
    • Usage: man [command]

Variables

name="John"
echo $name  # see below
echo "$name"
echo "${name}!"

Quotes

name="John"
echo "Hi $name"  #=> Hi John
echo 'Hi $name'  #=> Hi $name

Functions

get_name() {
  echo "John"
}

echo "You are $(get_name)"

Vim Command Reference Guide

Opening and Saving Files

  • vim: Open a file in Vim
    • Usage: vim [filename]
  • :w: Save changes
  • :wq or :x: Save changes and quit
  • :q!: Quit without saving (force quit)

Editing

  • i: Insert mode (insert before the cursor)
  • a: Append mode (insert after the cursor)
  • o: Open a new line below the current line and enter insert mode
  • O: Open a new line above the current line and enter insert mode
  • x: Delete character under the cursor
  • dd: Delete the current line
  • yy: Yank (copy) the current line
  • p: Paste the yanked or deleted text after the cursor
  • u: Undo
  • Ctrl + r: Redo

Search and Replace

  • / [search_term]: Search forward
  • ? [search_term]: Search backward
  • n: Move to the next search result
  • N: Move to the previous search result
  • :%s/search_term/replace_term/g: Replace all occurrences of a term in the entire file
  • :%s/search_term/replace_term/gc: Replace all occurrences of a term in the entire file but with confirmation on replace

Exiting Vim

  • :q: Quit (if there are no unsaved changes)
  • :q!: Quit without saving
  • :wq or :x: Save changes and quit

Help

  • :help: Open Vim’s built-in help

Additional Resources