Skip to content

Instantly share code, notes, and snippets.

@raisedadead
Created April 15, 2024 07:37
Show Gist options
  • Save raisedadead/ce6e5d27cc2c7136fb1158062f0ada73 to your computer and use it in GitHub Desktop.
Save raisedadead/ce6e5d27cc2c7136fb1158062f0ada73 to your computer and use it in GitHub Desktop.

Shell Command Shortcuts and Tricks Cheat Sheet

History Expansion

  • !!: Repeats the last command.
  • !$: Last word of the previous command.
  • !^: First argument of the previous command.
  • !n: Repeats the nth command in your history.
  • !-n: Repeats the command n places back in the history list.
  • !string: Executes the most recent command starting with 'string'.

Brace Expansion

  • {a,b,c}: Expands into a b c (useful for manipulating multiple files).

Tilde Expansion

  • ~: Home directory.
  • ~username: Home directory of username.

Variable Expansion

  • $variable: Value of variable.
  • ${variable}: Same as above but useful for appending characters immediately after the variable without ambiguity.

Command Substitution

  • $(command): Runs command and uses its output.
  • `command`: Older syntax for command substitution.

Arithmetic Expansion

  • $((expression)): Evaluates arithmetic expression and substitutes the result.

Wildcard Expansion (Globbing)

  • *: Matches any characters.
  • ?: Matches any single character.
  • [abc]: Matches any one character listed.

Quoting

  • " ": Double quotes (special characters except $, \, and backticks lose special meaning).
  • ' ': Single quotes (everything is taken literally).

Redirection and Pipes

  • >: Redirects output to a file, overwriting existing contents.
  • >>: Appends the output to the end of a file.
  • <: Takes input from a file.
  • |: Directs output of one command to another.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment