This is a list of things I either think are neat, or things I'm always Googling.
Locale Settings:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
Process Tree:
pstree -p
Create a .gitkeep
file in all empty directories:
find . -type d -empty -print0 | xargs -0 -I{} touch {}/.gitkeep
Remove all files in /tmp older than 2 days
find /tmp -maxdepth 1 -type f -mtime +2 -exec rm -i "{}" \;
Shell Startup Files:
-
Linux/Bash/TTY:
/etc/profile
→ first of~/.bash_profile
,~/.bash_login
,~/.profile
that exists -
Linux/Bash/XTerm:
/etc/bash.bashrc
→.bashrc
-
Linux/Bash/Scripts (#!/usr/bin/env bash):
looks for$BASH_ENV
var and sources the expansion of that variable -
Linux/ZShell/TTY:
/etc/zshenv
→~/.zshenv
→/etc/zprofile
→~/.zprofile
→/etc/zshrc
→~/.zshrc
→/etc/zlogin
→~/.zslogin
(/etc/z*
is the default; however/etc/zsh/z*
seems to be common (at least on Ubuntu)) -
Linux/ZShell/XTerm:
/etc/zshrc
→~/.zshrc
-
Linux/ZShell/Scripts (#!/usr/bin/env zsh):
/etc/zshenv
-
OSX/Bash/TTY/XTerm:
/etc/profile
→ first of~/.bash_profile
,~/.bash_login
,~/.profile
that exists -
OSX/Bash/Scripts (/usr/bin/env bash):
looks for$BASH_ENV
var and sources the expansion of that variable -
OSX/ZShell/TTY/XTerm:
/etc/zshenv
→~/.zshenv
→/etc/zprofile
→~/.zprofile
→/etc/zshrc
→~/.zshrc
→/etc/zlogin
→~/.zslogin
-
OSX/ZShell/Scripts (/usr/bin/env zsh):
/etc/zshenv
Setting your hostname—Debian and Ubuntu:
-
Edit
/etc/hostname
and add you unqualified hostname, e.g.,echo "parabola" > /etc/hostname
-
Run
hostname -F /etc/hostname
to update your hostname -
Edit
/etc/hosts
:127.0.1.1 parabola.tylercipriani.com parabola localhost
Cronjob Time Syntax:
- m h dom m dow <what_to_do>
- m - minute(0–59)
- h - hour(0–23)
- dom - day-of-month(0–31)
- m - month(0-11)
- dow - day-of-week(0–6)
- <what_to_do> - anycommand
Send mail
echo "Message Body" | mail -s "Mail Subject" [email protected]
Send mail to multiple people:
echo "Message Body" | mail -s "Mail Subject" -c "[email protected] [email protected]" [email protected]
Git show contents of stash
git stash show -p stash@{1}
IPTables
-
Block an IPAddress
iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP
-
Insert a rule to allow inbound tcp traffic on port 8000 (puts the rule at the top)
iptables -I INPUT -i eth0 -p tcp --dport 8000 -j ACCEPT
Tar (Tape Archive Utility)
-
Create gzipped tar from file or directory
tar -cvzf tarfile.tar.gz directory file otherfile
-
Create bzipped tar file from file or directory
tar -cvjf tarfile.tar.bz2 directory file otherfile
-
List contents of tar.gz file
tar -tvzf tarfile.tar.gz
Wget/cURL
-
Rip a whole site with wget:
wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains <domain-name> --no-parent http://<domain>
-
Upload file via cURL
curl -X 'POST' -H 'Accept: application/json' -F 'file_name=Test File' -F 'file_contents=@/path/to/file.type' www.example.com/file/add
-
Fill login form via cURL
curl -X 'POST' -F 'username=tyler' -F 'password=pass123' www.example.com/login
MySQL
-
Single DB Dump
mysqldump --compress -h localhost --quick --single-transaction [db_name] > [dumpfile]
-
Nice DB Dump
mysqldump -h localhost -u [username] -p --add-drop-database --skip-comments --routines --compress --quick --single-transaction --databases [db_name] > [dumpfile]
-
Dump tables that match pattern:
mysqldump -h localhost --quick --single-transaction [db_name] `mysql -ND [db_name] -h localhost -e "show tables like '[pattern]'" | awk '{ printf $1" " }'` > dumpfile.sql
Debug bash scripts, add:
set -x
Forward new port in existing SSH session:
<newline>
~C
ssh> ?
List currently established, closed, orphaned and waiting TCP sockets:
ss -s
netstat -tlnp
vs ss -ln
$ time netstat -tlnp 127 ↵
netstat -tlnp 0.00s user 0.02s system 97% cpu 0.016 total
$ time ss -ln
ss -ln 0.00s user 0.00s system 83% cpu 0.005 total
Check disk I/O:
vmstat 1 10
What's using disk I/O:
dstat --top-io --top-bio
Show io per-device (needs sysstat package on debian):
iostat -sk 2
Linux Fun Crap
-
Generate a list of your most used commands—
history | sed "s/^[0-9 ]*//" | sed "s/ *| */\n/g" | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 100 > commands.txt
-
The Useless Use of
cat
Award (partmaps) -
Terminal Keynote (Ruby) (github)
-
Boom. Motherfucking Text Snippets on the command line (zachhholman)
-
Spark sparklines for your shell (zachholman)
-
Lolcat (github)
-
cowsay (github)
-
Ponysay (github)
-
FIGlet (figlet)
-
Libcaca (caca.zoy)
-
Toilet (caca.zoy)
-
Boxes (thomasjensen)
-
Cadubi (perl) (langworth)
-
img2txt (hit9)
-
Nyancat (klange.github)
-
CMatrix (asty)
-
janbrennen rice (github)
-
dotshare.it (dotshare.it)
-
linux logo (freecode)
-
bb (aa-project)
-
Powerline Font symbols (powerline)
-
Stupid Programmer Tricks/Starwars gifs (rarlindseysmash)