Bash Commands

From Adam Colton
Jump to navigation Jump to search

Resources

Quizzes

  • Folder hierarchy concepts (ls, cd, .., ~, /)
  • Basic text manipulation
  • File manipulation
  • Output direction (>, < |)
  • Utils
  • More Text manipulation (sort, uniq, nl)
  • Processes
  • Remote
  • Sed
  • Grep
  • Awk
  • rsync
  • Scripting

Filename aliasing

  • * match 0 or more characters
  • ? match any single character
  • [abc...] match any enclosed character, hyphen to specify range
  • [!abc...] not any character
  • ~ home directory of current user
  • (a|b) pattern a or b
  • f{oo,u}bar generates foobar or fubar
    • echo {1...10} will list numbers 1 through 10
  • quoting
    • ": $, ' ", \
    • ': only '

Command Forms

  • cmd & - execute in background
  • cmd1 ; cmd2 - execute multiple commands
  • {cmd1; cmd2;} execute commands as a group in the current shell
  • (cmd2; cmd2) execute commands as a group in a subshell (I don't know what this means)
  • cmd1 | cmd2 pipe output from cmd2 as intput to cmd 2
  • cmd1 `cmd2` use cmd2 output as arguments to cmd1
  • cmd > file send output to file and overwrite
  • cmd &> file send output and errors to file and overwrite
  • cmd >> file send output to file and append
  • cmd < file take input for cmd from file
  • (date; ls) > file - All output is sent to the file
  • cmd | tee files send to standard out and files

Command History

  • !! previous command
  • !n command n
  • !-n command n ago
  • !string most recent command that starts with stirng
  • !?string[?] most recent command that contains string

Terminal Commands

  • cd
  • pwd

Special Operations

  • <
  • >
  • |
  • >>
  • tee
  • .
  • !!
  • -
  • ~, /
  • ..

Control Characters (all are ctrl+)

  • A: beginning of line
  • C: terminate foreground job
  • E: end of line
  • R: Backward search in history for text in command
  • W: Erase backwards to whitespace
  • Z: Pauses foreground job
  • L: clear the screen
  • U: clears everything from the cursor to the beginning of the line
  • K: clears everything from the cursor to the end of the line
  • T: swap the last two characters before the cursor
  • B: move the cursor backward one character
  • F: forward one character
  • J or M: enter
  • N: Next in history (down arrow)
  • P: Previous in history (up arrow)
  • O: Enter the current command and put in back on the command line for further editing
  • Y: Paste from ^W, ^K or ^U like commands

Text Processing

  • tr [options] set1 [set2]
    • alnul, alpha, blank, digit, space, upper
    • lower to upper "tr a-z A-Z"
    • -d: delete, -s:squeeze(repeats the operation until no changes occur), -cs
  • uniq
    • unique a file by line
    • -c: print the number of times each line occurred
    • -i: ignore case
    • -d: print only duplicated lines
    • -u: print only unique lines
    • -w N: check only N characters
  • sort
    • -b: ignore leading blanks
    • -f: ignore case
    • -r: Reverse
    • -u: unique
  • wc
    • Shows the line, word and character count
    • -c: print only the byte count
    • -w: print only the word count
    • -l: print only the newline count
    • Example: grep FIXME *.c | wc -l count all the instance of FIXME in *.c files in the current directory
  • fold
  • nl
  • diff

Other

  • ls
  • less
  • cat, tac
  • man
  • head
  • tail
  • bc
  • rev
  • echo
    • -n: Do not print the trailing newline
  • mapfile

Power Tools

  • sed
  • grep
  • rsync

Files and Folders

  • mv
  • rm
  • mkdir
  • cp
  • rmdir
  • chmod
  • ln

Utils

  • cal
  • date
  • find
  • gzip
  • tar
  • time

Remote

  • ssh
  • screen
  • ftp
  • ping
  • rcp
  • scp
  • wget

Processes

  • bg
  • fg
  • jobs
  • kill
  • ps
  • coproc

Scripting

  • if
  • wait
  • case