Commands
CommandDescription
Alpine Linux
apk fetch --recursive aws-cliDownload all of the apk files needed to install "aws-cli" to current directory
apk add --no-network --allow-untrusted *.apkInstall apk files hosted in current directory. Useful for installing apk packages in an environment with restricted networking for debugging.
Firefox Developer Toolbar
screenshot --selector div.<classname> <filename>Takes a screenshot of the first div found with class <classname> and saves a screenshot in the downloads folder with the name <filename>.png. Other css-style selectors work too.
Kubernetes
kubectl apply -k $PWD --dry-run=serverTest a k8s kustomization directory against the currently configured k8s cluster
Linux
sed ':a; N;s/\n/,/; ta;'concat all lines together with commas
sed 's/find/replace/g'replace all occurances of "find" with "replace"
sed 's/find.*$/replace/g'replace everything from "find" to end of line with "replace"
pushd .push directory onto the directory stack
popdpop directory from directory stack (cd to pop'd directory)
until <command>; do sleep 5; donetry to run command, repeat every 5 seconds until it succeeds
sudo iptrafdisplays network usage statistics
ssh <user>@<host> -Llocalhost:<local port>:<remote address>:<remote port>Tunnel a connection from localhost (on specified port) through host to remote address on specified port
convert <src image> -selective-blur 10x3+02% -despeckle -resize 2000 <dest image>selectively blur lower contrast sections of image, despeckle remaining parts, and resize
awk '{ print $4}'Grab 4th white-space deliminated section of text
awk '{ if ($0-prev<0){print $0"-"prev"\t"$0-prev;} prev=$0; }'print info about two lines where the first line is greater than the second line
awk '{ sum+=$0 } END { print sum }'calculate sum of lines
pv file.txt | somecommandmonitors how fast data is being transferred to pipe.
somecommand | pv | anothercommandmonitors how fast data is being sent through pipe from one program to another.
cat -v <filename>Output file but display non-printing characters with ^ and M- notation.
host -t a <domain name>Return list of ip addresses associated with the domain.
convert file.png -background white -flatten file.jpgConvert a transparent png to a jpg. Sets background of image to white.
cat <filename> | pv -qL 2kRead a file but limit the rate to 2kb/s
cd -Switch to last directory
rsync --partial --inplace --progress --rsh=ssh <user>@<host>:<remote file> <local file>finish transferring remote file to local file
kill -s SIGTSTP <pid>; sleep 60; kill -s SIGCONT <pid>;Pause a process. Sleep 60 seconds. Resume paused process.
complete -f -X '!*.sql' compressBackupregister auto-complete options for 'compressBackup'. Auto-complete options are files that match the specified pattern.
egrep -n '\"([^\"]|\\\")*\"' --color=alwayshighlight quoted strings (ignore \" inside quotes)
t=$(ls); echo $t | sed 's/ /\n/g'; until false; do ot=$(echo "$t" | awk '{ print "^"$0"$" }' | sed ':a; N;s/\n/|/; ta;'); t=$(ls); echo $t | sed 's/ /\n/g' | egrep -v "$ot"; sleep 2; doneBasically a tail -f for directory entries. Gets a list of directory contents and then checks again (omitting entries that were there the last time the contents were checked)
find . -type f -print0 | xargs -P 4 -n 100 -0 <command>Pass all files in current directory (and subdirectories) into <command>. Run 4 instances of specified command at a time and give each instance 100 files to handle. (Ex: <command> "shred -vzu -n1" will securely delete all files in the current directory)
find -name '*.jar' | xargs -n1 unzip -l | egrep '(^Archive|SQLServerDriver)' (From Jens) you probably use something like this already sometimes, but I found myself using it again, looking into a classpath problem, and I thought you might find it useful.
ssh <user>@<host> -D <local port>create socks proxy on local port through host
curl -v ipecho.net/plain --connect-timeout 30 --socks5 <ip>:<port>Test socks5 proxy.
mount -t cifs -o user=<username> //<ip address>/<share> <mountpoint>Mount network share to filesystem
cat <tar file> | tar -x --to-command="bash -c '(md5sum -; echo \"\$TAR_FILENAME\")| sed \":a; N;s/*-\n//; ta;\"'"Calculate md5 hash of each file in tarball.
ip route add <ip> via <gateway> dev wlan0Force all traffic to <ip> to go through <gateway> using the wireless link (wlan0). Can be used to bypass vpn for a specific ip address.
awk '{ if (sub(/\/\*\!\*\/;/,"")) {print $0;} else {printf("%s",$0);} }'Join all lines that don't end with "/*!*/;" (useful for analyzing mysql binary logs)
coproc <command1>; <command2> <&${COPROC[0]} >&${COPROC[1]}; wait $COPROC_PIDpipe output of <command1> into <command2> and pipe output of <command2> back into <command1>. (Ex: using commands "nc -l 22" and "nc 10.1.1.10 22" will form a simple tcp proxy where a client can connect to port 22 and have all communications forwarded to 10.1.1.10)
cat style.css | tr -d '\n\r\t' | sed -r 's/ +/ /g' | sed -r 's/([;:,]) /\1/g' > style.min.cssSimple minify for css
stdbuf -o L <command>Change default buffering mode of <command> to line buffering
strace -t <command>Trace all of the system calls executed by a given command
gcore <pid>Generate a core-dump of the process with the given pid
cat <file> | split -n <lines> --filter=<command>Send <lines> number of lines into <command> at a time. <command> will restart after max lines have been processed.
curl -v --resolve <domain name>:443:<ip> https://<domain name>/ip.ashxConnect to <domain name> using a specified ip address (instead of performing DNS lookup)
identify -format "%#" "image.jpg"Print a hash of the imagedata. It should be the same even between different image formats (like between jpg and png) if the image data is the same.
lsof -i -P -n -sTCP:LISTENList open TCP ports
ssh user@somewhere.com -J other@jump.com:1234Connect to somewhere.com via a ssh connection to jump.com
ssh -o ProxyCommand="nc -x localhost:1234 %h %p" user@somewhere.comConnect to somewhere.com using a socks proxy at localhost:1234
ldapwhoami -vvv -h <domain> -p 389 -D <user> -x -WTest ldap connection for <user> to <domain>. Will need to enter password on stdin. Alternatively, you can use a lowercase "-w" and add the password as a command argument.
prlimit --fsize=1000000 -p 12345Set ulimit filesize of running process to 1000000 bytes.
strace -s 10000 -f -tt -p <pid>Track all system calls for process #<pid> and its children. Include up to 10,000 characters in the syscall arguments.
cat <filename> | xclip -selection clipboardCopy contents of <filename> into system clipboard
xclip -selection clipboard -oWrite contents of system clipboard to stdout
dig @8.8.8.8 hostname.tldPerform a dns lookup directly against 8.8.8.8.
socat tcp-listen:8080,reuseaddr,fork tcp:example.com:8081Run a tcp proxy. Forwards all traffic on local port 8080 to example.com:8081
tcpdump "udp port 123" -vv -s0 -i eth0Monitor eth0 for udp traffic on port 123
package-cleanup --oldkernels --count=1(centos) Automatically remove older kernels to free up /boot volume.
ldapsearch -o ldif-wrap=no -h acme.org -p 389 -D admin@acme.org -x -W -b "cn=users,dc=acme,dc=org" "sAMAccountName=john.doe" memberOfSearch LDAP for a user with the account name "john.doe" and print the groups they are a member of.
chef-client -o <cookbook1>::<recipe1>,<cookbook2>::<recipe2>Run chef-client with two specific recipes (ignoring current runlist from server)
sed 's/\xc2\xa0/ /g'Replace unicode non-breaking space with a regular space
sudo -u nobody /bin/bashGet a bash shell running for a user without a default shell
openssl s_client -showcerts -connect example.com:443 < /dev/nullConnect to a server and attempt to verify its ssl certs.
ssh-keygen -l -E md5 -f ~/.ssh/id_rsa.pubGet public key MD5 fingerprint in hex
color=yellow; echo "$color ${color^} ${color^^} ${color,} ${color,,}"Capitalize nothing, first letter, all. Lowercase first letter, all.
dive 0123456789abExamine contents of docker image and identify potentially wasted space
fallocate -dv /path/to/file"Dig holes" in file to save disk space. Converts a file to a sparse file by deallocating runs of zeros from backend disk.
kpartx -av disk_image.imgLoad a disk image with multiple partitions and expose partitions as individual loopback devices.
upower --dumpPrint a list of power-related devices and display their battery info along with other data.
docker inspect -f $'{{.Name}}\t{{.GraphDriver.Data.MergedDir}}' $(docker ps -aq)Get root volume of docker containers
nmap -d --script +ssl-enum-ciphers -p 1234 10.1.2.3Check supported ciphers on service behind given ip/port
curl https://hub.docker.com/v2/namespaces/library/repositories/openjdk/tags?page_size=100&name=alpine&page=2Fetch docker image information for "openjdk" images with tag "alpine" (page 2)
Microsoft SQL Server
select t.name as table_name ,i.name as index_name ,i.type_desc as index_type ,s.row_count ,8*case when (s.index_id=0 or s.index_id=1) --if heap or clustered index, take at face value then (s.in_row_data_page_count+s.lob_used_page_count+s.row_overflow_used_page_count) else (0) end as data ,8*case when (s.index_id=0 or s.index_id=1) --if not heap or clustered index, all data is index data then (s.used_page_count-s.in_row_data_page_count-s.lob_used_page_count-s.row_overflow_used_page_count) else (s.used_page_count) end as index_size ,8*(s.used_page_count) as total_used from sys.dm_db_partition_stats s join sys.tables t on s.object_id=t.object_id join sys.indexes i on s.object_id=i.object_id and s.index_id=i.index_id order by t.name;Get size information from all tables in the current database. Includes approximate row count, data size, index sizes, and total size.
select t.table_name, max(t.row_count) as row_count, sum(t.data) as data, sum(t.index_size) as index_size, sum(t.total_used) as total_used from ( select t.name as table_name ,i.name as index_name ,i.type_desc as index_type ,s.row_count ,8*case when (s.index_id=0 or s.index_id=1) --if heap or clustered index, take at face value then (s.in_row_data_page_count+s.lob_used_page_count+s.row_overflow_used_page_count) else (0) end as data ,8*case when (s.index_id=0 or s.index_id=1) --if not heap or clustered index, all data is index data then (s.used_page_count-s.in_row_data_page_count-s.lob_used_page_count-s.row_overflow_used_page_count) else (s.used_page_count) end as index_size ,8*(s.used_page_count) as total_used from sys.dm_db_partition_stats s join sys.tables t on s.object_id=t.object_id join sys.indexes i on s.object_id=i.object_id and s.index_id=i.index_id ) t group by t.table_name order by sum(t.total_used) desc;Get size information from all tables in the current database (grouped by table name). Includes approximate row count, data size, index size, and total size.
select t.name,i.name,s.* ,t.*,i.* from sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'DETAILED') s left join sys.tables t on s.object_id=t.object_id left join sys.indexes i on s.object_id=i.object_id and s.index_id=i.index_id order by t.nameGather information on indices for the tables in the current database. Shows fragmentation amount and % of space used.
Oracle
explain plan for select * from table; select PLAN_TABLE_OUTPUT from TABLE(DBMS_XPLAN.DISPLAY());Show the execution plan for a given query.
OSX
screencapture -R 130,185,1600,900 t.pngTake screenshot of specific coordinates of screen and save as png image
pmset -g accps -xmlFetch battery information for laptop and connected bluetooth devices in XML format
Tomcat
java -cp catalina.jar org.apache.catalina.util.ServerInfoPrint server info for tomcat (needs to be run from tomcat/lib folder)
VIM
:%s/search/replace/gSearch and replace in file
:{range}sortsorts the selected range (range may be selected by highlighting section and pressing ':')
"kyyCopy line into register "k"
"kpPaste contents of register "k"
zfCreate fold (over selected area)
zoOpen fold
zcClose fold
"*yCopy into system clipboard
:syntax sync fromstartrecalculate syntax from beginning of file (helpful when syntax highlighting gets messed up)
<ctrl> lrecalculate syntax
:map <f2> :w<cr>:!tmux send-keys -t left "<command>" C-m<cr><cr>send <command> to left tmux window by pressing f2
:w !sudo tee %Save file with sudo (in case you forgot to open a file with elevated permissions)
:map <F5> :w !sqlite3 temp.db \| column -t -s"\|" \| less<cr>Run query using current file contents against sqlite database
:%s/\s\+$//gRemove all trailing spaces from current file
Visual Studio
<ctrl> UMake text lowercase
<ctrl> <shift> UMake text uppercase
<ctrl> k dAuto-format entire document
<ctrl> k fAuto-format selected section
Windows
mklink /J linkName targetcreate symbolic link for directories
<windows> <left>/<right>snap window to left/right (works with dual monitors as expected)
ipconfig /flushdnsClear windows DNS cache
tasklist /S <remote machine>Display a list of the processes running on a remote machine (uses your current credentials).
wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime,WorkingSetGet information about all processes running on machine. Additional columns are available. (See all columns by omitting everything after "get")
ipconfig /registerdnsRenew dns client registration (tell network what IP your computer currently has)
psexec -i -s cmd.exeOpen a command prompt running as the "Local System" account (or "des-w7-garhan$" as seen in the permissions views)