Skip to content

Instantly share code, notes, and snippets.

@rubbsdecvik
Created September 2, 2016 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubbsdecvik/431adebd1daa2aecfcc333d3a433e9c4 to your computer and use it in GitHub Desktop.
Save rubbsdecvik/431adebd1daa2aecfcc333d3a433e9c4 to your computer and use it in GitHub Desktop.

Stupid Unix Tricks

Real Basics

Keyboard Shortcuts

  • Arrow keys do what you'd expect
  • ctrl + a will put you at the beginning of the line
  • ctrl + e will put you at the end
  • ctrl + w deletes previous word (space delimited)
  • tab will auto-complete commands (requires bash-completion)
  • ctrl + l forces a screen redraw
  • ctrl + r recursively searches through history
  • ctrl + c stops

Helpful Bashisms

  • !! - substitute in last command here
  • !$ - place last argument of last command here
  • ./ - current directory
  • cd - change to home directory
  • cd - - Change to last directory
  • ^foo^bar - Run last command replacing string foo with bar
  • fc - Open last command in $EDITOR. Execute upon save+quit
  • ctrl+x; e - Open current command line in $EDITOR

Helpful Things

Pipe Viewer

Replacement for cat that shows file progress via stderr

pigz

Parallel gz. Compression sizes are similar if not same, but uses multiple cores

pigz -c ./ChessData.tar > ChessData.tar.pigz.gz

Same input Multiple outputs

You can send the same input to multiple outputs without having to run multiple commands

pv ./ChessData.tar | tee >(gzip - > /tmp/ChessData.tar.gz) >(bzip2 - > /tmp/ChessData.tar.bz2) | xz - > /tmp/ChessData.tar.xz

flock

Use flock to make a lock with a file. This helps with cron jobs

* * * * * /usr/bin/flock -w 0 /path/to/cron.lock /usr/bin/php /path/to/cron.php

Clipboard access in CLI

Put a file into the clipboard

cat file.txt | xclip -selection clipboard -in

Put clipboard into file

xclip -selection clipboard -out > file.txt

Links

Command Line Tools Can Be 235x Faster Than Your Hadoop Cluster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment