Skip to content

Instantly share code, notes, and snippets.

@yasushiyy
Last active December 14, 2015 07:09
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 yasushiyy/5048198 to your computer and use it in GitHub Desktop.
Save yasushiyy/5048198 to your computer and use it in GitHub Desktop.
Command-Line Hacks

Useful shell snippets

Change Extension

change .doc to .txt (for whatever reason)

for name in *.doc
do
  mv "$name" "${name%.doc}.txt"
done

Fixed-Width CSV

Align CSV entries to view in a terminal.

$ cat << EOF | awk -F"," '{printf "%10s %-10s\n", $1, $2}' 
111,AAA
22222,BBBBB
EOF

Result:
      111 AAA
    22222 BBBBB

Loop in shell

for i in `seq 1 99`
do
  echo "ahh!"
done

tar options

list file in tar.gz

gunzip -c xyz.tar.gz | tar vtf -

extract one file in tar.gz

gunzip -c xyz.tar.gz | tar xf - -I filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment