* shell uncompress .xz files unxz * shell create empty image file fallocate -l 1G test.img * shell show top five CPU consuming processes ps aux | sort -rk 3,3 | head -n 6 * shell show duplicates in first column awk '{print $1}' hashes.log | sort | uniq -cd * shell convert list of timestamps to dates grep -F 'quit' bla.txt | cut -f2 -d" " > new.txt #list of timestamps while read in; do date -d @"$in"; done < new.txt * shell get Xorg version X -version * shell tar compress directory tar -zcvf archive-name.tar.gz directory-name * shell ftp upload(from secure mobile) ftp -inv IP < * shell format sql query sqlformat --reindent --keywords upper --identifiers lower file.sql * shell launch xterm with geometry DISPLAY=:0.0 xterm -geometry 80x24+10+10 * shell OpenGL test DISPLAY=:0.0 glxgears -fullscreen * shell ssh to remote machine with remote graphics enabled ssh -X blabla arandr --randr-display :0.0 * shell manually set window to a resolution DISPLAY=:0.0 wmctrl -r chrome -b toggle,fullscreen DISPLAY=:0.0 wmctrl -r chrome -e 0,0,0,1080,3840 * shell i3 wm send restart/any config command DISPLAY=:0 i3-msg restart * shell i3 reload with debug DISPLAY=:0 i3-msg 'debuglog on; shmlog on; reload' * i3 exit fullscreen mode by default Alt+f * shell xrandr check DISPLAY=:0.0 xrandr -q * shell qemu load i386 raw image qemu-system-i386 -net nic,model=rtl8139 -net user -m 512M -boot order=d -drive file=NAME.img,format=raw * shell exclude grepping self ps aux's own process ps aux | grep "[f]nord" * shell SOCKS proxy using tunnel ssh -N -D 2001 -p port username@servername * shell tar.gz folder tar -zcvf archive-name.tar.gz directory-name * shell diff two directories recursively diff -rq dir1 dir2 * shell see all userland processes ps a --ppid 2 -p 2 --deselect * shell scan for wifi networks sudo iwlist wlan0 scan * shell print last line tail -1 * shell cut by tab cut -d' ' -f 1 * shell remove leftover packages tar -zcvf archive-name.tar.gz directory-name * shell diff two directories recursively diff -rq dir1 dir2 * shell see all userland processes ps a --ppid 2 -p 2 --deselect * shell scan for wifi networks sudo iwlist wlan0 scan * crontab reboot every 5th minute */5 * * * * sudo /sbin/reboot * shell start without a cursor startx -- -nocursor * shell change layout in X DISPLAY=:0.0 setxkbmap -layout dk * shell change layout on tty sudo loadkeys dk * shell test sound over HDMI speaker-test -c 2 -r 48000 -D hw:0,3 * shell logrotate manually logrotate -d [your_config_file] * shell nmap scan LAN for mac addresses(fast) nmap -sP 192.168.0.* * shell exit virtualenv deactivate * shell split flac in cue shnsplit -f file.cue -t %n-%t -o flac file.flac * shell docker stop/rm containers docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) * shell docker delete dangling images docker rmi $(docker images -f "dangling=true" -q) * shell docker hub get docker file https://hub.docker.com/r/jasonrivers/nagios/~/dockerfile/ * shell docker clean exited containers docker ps --filter "status=exited" | awk '{print $1}' | xargs --no-run-if-empty docker rm * shell docker get container ip docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id * shell docker good single user jupyterhub docker run jupyterhub/singleuser * shell docker get pids for container docker top 79fb7ddd1f1e * shell untar tar.gz tar -xzf file * shell delete duplicate files fdupes -dN . * shell tar directory tar -czvf my_directory.tar.gz -C my_directory . * shell checksum recursively find / -type f -print0 | xargs -0 md5sum > /checksums_backup.md5 * shell read/write dstructive test badblocks -wsv /dev/sdd * shell get UUID of ext filesystem blkid /dev/sda1 * shell stop dmesg spilling in console sudo dmesg -n 1 * shell get BIOS version cat /sys/class/dmi/id/bios_version * shell stop process kill -SIGSTOP * show fps counter chromium --show-fps-counter * shell extract package from system dpkg-repack * SBCL disable debugger from inside (defun debug-ignore (c h) (declare (ignore h)) (print c) (abort)) (setf *debugger-hook* #'debug-ignore) * elisp insert some formatted text in a loop (loop for key from 0 below 10 do (insert (format "bakabaka %d desu \n" key))) * execute program with gdb, go to start, step opcode by opcode use: https://github.com/cyrus-and/gdb-dashboard gdb break _start run si * shell copy filesystem from place to place rsync -avxHAX --progress / /new-disk/ * shell show to which package a file belongs to dpkg -S /bin/ls * shell running 64 bit UEFI qemu with OVMF and ssh port forwarded qemu-system-x86_64 -L . -m 1024 -hda /dev/sdb -localtime \ -net nic,model=rtl8139 \ -net user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9,hostfwd=tcp::60022-:22 \ -soundhw ac97 -usb -usbdevice tablet * shell ldd on windows exe objdump -p *.exe | grep -F 'DLL Name:' * shell reset usb device echo 0 > /sys/bus/usb/devices/1-4.6/authorized echo 1 > /sys/bus/usb/devices/1-4.6/authorized * configure for 32 bit on 64 bit host ./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32" * chrome task manager shift+enter * chrome task manager shift+enter * gcc/g++ good optimization flags for x86_64 -m64 -O3 -fomit-frame-pointer -funroll-loops -fomit-frame-pointer -march=native -mtune=native * firefox download blob video in firefox inspect element network play video click (large) octet-stream request use the link to download .ts stream * firefox search bar tricks ^ for matches in your browsing history. * for matches in your bookmarks. % for matches in your currently open tabs. # for matches in page titles. @ for matches in web addresses. * firefox disable addon signitures xpinstall.signatures.required * emacs insert shell command C-u M-! * emacs pretty print xml M-x sgml-mode M-x sgml-pretty-print * emacs reload file revert-file * emacs execute sexp in go to end of sexp and hit C-x C-e * emacs replace on yank (delete-selection-mode 1) * emacs clear kill ring (setq kill-ring nil) * emacs see git(vc) log vc-print-root-log * emacs open new shell C-u M-x shell * emacs set font height (set-face-attribute 'default nil :height 100) * emacs remote shell with autocomplete C-x d /ssh:mger@iguana: open directory M-x shell delete path and leave /bin/bash * emacs XML pretty print sgml-pretty-print * python check TCP connection to address import socket TCP_IP = IP TCP_PORT = port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.close() * python shuffle list import random s = range(5) random.shuffle(s) * python resolve DNS import socket data = socket.gethostbyname_ex("google.com") print(data) * python wheel build/register/upload chain python setup.py bdist_wheel --universal twine register dist/* twine upload dist/* * python - encode/decode b64 from base64 import b64encode, b64decode b64encode(s[, altchars]) b64decode(s[, altchars]) * python utf8 # -*- coding: utf-8 -*- * python change directory import os os.chdir(path) * python get modules from files grep -h "import " *.py | unexpand | sed 's/import//' | sed 's/from.*//' | tr -d " " | sort | uniq * python venv create virtualenv python3 -m venv /path/to/new/virtual/environment * python trace function calls python3 -m trace --listfuncs traceit.py * python trace statements python3 -m trace --trace traceit.py * python convert notebook to python file jupyter nbconvert --to script notebook.ipynb * python check ssl trust store paths python -c "import ssl; print(ssl.get_default_verify_paths())" * python requests bundle to system ssl certs REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt * python multiprocess utilization from multiprocessing import Pool def f(x): while True: pass return x*x if __name__ == '__main__': NUM = 5 p = Pool(NUM) print(p.map(f, [1]*NUM)) * python get current datetime from datetime import datetime now = datetime.now() * python emergency reinstall pip curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py --force-reinstall * python get output from process from subprocess import getoutput getoutput("ls -l") * virtualenv create and activate e="testenv" virtualenv $e cd $e/bin source activate * postgres list all dbs \list or \l * postgres list all tables in the current database \dt * postgres list schemas in db \dn * postgres enable list view \x * postgres show table info(size, etc.) \dt+ table1 * postgres top 5 biggest tables SELECT table_name ,pg_relation_size(table_schema || '.' || table_name) as size FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') ORDER BY size DESC LIMIT 5; * postgres get current settings SELECT name, setting, source FROM pg_settings; * postgres log prefix log_line_prefix = '%t:%r:%u@%d:[%p]:' * postgres list roles \du * postgres superuser ALTER USER randomuser WITH SUPERUSER; * postgres list constraints SELECT con.conname FROM pg_catalog.pg_constraint con INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid INNER JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace WHERE nsp.nspname = 'schema name'; * postgres get column names from table SELECT column_name FROM information_schema.columns WHERE table_schema = 'your_schema' AND table_name = 'your_table'; \d+ schema.table * postgres get triggers on schema SELECT distinct(trigger_name) FROM information_schema.triggers WHERE trigger_schema = 'MY_SCHEMA'; SELECT distinct(event_object_table) FROM information_schema.triggers WHERE trigger_name = 'TRIGGER_NAME'; * git interactive rebase - amend author git rebase -i -p git commit --amend --author "author " --no-edit git rebase --continue * git get origin url git config --get remote.origin.url * git pull submodules git submodule update --init --recursive * git set ssh key per repository git config core.sshCommand "ssh -i ~/.ssh/id_myclient" * bash fail on error set -e * apt add key to sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3C962022012520A0 * apt upgrade a specific package apt-get install --only-upgrade build-essential * apt list manifest apt list --installed * apt search repos for file and package it belongs to apt-file update apt-file find htop * apt upgrade ubuntu system apt-get install update-manager-core do-release-upgrade conf: /etc/update-manager/release-upgrades * apt remove leftover packages sudo apt-get remove --purge $(sudo dpkg -l | grep "^rc" | awk '{print $2}' | tr '\n' ' ') * apt virtual monitor/server apt-get install xvfb Xvfb -shmem -screen 0 1280x1024x24 DISPLAY=:0 xdpyinfo ^verify * apt list package dependencies apt-cache depends python * apt get software version package - ubuntu sudo apt-cache show libc6 * apt get not-installed-package deb links sudo apt-get install --yes --no-download --reinstall --print-uris xdotool out: 'http://ports.ubuntu.com/pool/universe/x/xdotool/libxdo3_3.20130111.1-3.1_armhf.deb' libxdo3_1%3a3.20130111.1-3.1_armhf.deb 17644 MD5Sum:10057d4dbbdcee72f32bbc109ff9863d 'http://ports.ubuntu.com/pool/universe/x/xdotool/xdotool_3.20130111.1-3.1_armhf.deb' xdotool_1%3a3.20130111.1-3.1_armhf.deb 35606 MD5Sum:a84b1b4530df83adfe0a7ca594533fe0 * hbase console basics create 'test', 'cf' describe 'test' put 'test', 'row1', 'cf:a', 'value1' scan 'test' get 'test', 'row1' disable 'test' #to configure table enable 'test' drop 'test' count 'test' * hbase list all tables list * schroot a jail sudo debootstrap --variant=buildd --arch amd64 xenial /mnt/apache/ http://de.archive.ubuntu.com/ubuntu/ apt apt install nano in schroot.conf: [apache] description=Apache rewrite enviroment directory=/mnt/apache users=root root-groups=root schroot -c apache deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates main restricted deb http://de.archive.ubuntu.com/ubuntu/ xenial universe deb-src http://de.archive.ubuntu.com/ubuntu/ xenial universe deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates universe deb http://de.archive.ubuntu.com/ubuntu/ xenial multiverse deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates multiverse * number processes per user ps haux Ou | cut '-d ' -f1 | uniq -c * hive drop external table with data ALTER TABLE external_hive_table SET TBLPROPERTIES ( 'EXTERNAL'='FALSE'); DROP TABLE external_hive_table; * airflow run dag from console airflow run dag_1 task_1 2018-8-27 * R read csv table mydata <- read.table("test.csv", header=TRUE, sep=",", row.names="id") * R list installed packages ip = as.data.frame(installed.packages()[,c(1,3:4)]) ip = ip[is.na(ip$Priority),1:2,drop=FALSE] ip * R plotly plot btc_price <- read.table("btc_price.csv", header=F, sep=",") colnames(btc_price) <- c("date", "price") btc_price <- data.frame(as.Date(btc_price$date), btc_price$price) colnames(btc_price) <- c("date", "price") p <- plot_ly(x = btc_price$date, y= btc_price$price, mode = "lines") p * R summary for most data types summary(data) * R get times out of a time series time(data) * R specify slice of frame data[c(107:365),] * R install package install.packages("mypackage") * R get package version packageVersion("RCurl") * radare2 cheatsheet s 0x0000 - go to 0 pd 2 - print 2 instructions from current address px 20 - print 20 hex bytes pr 20 - print (text) bytesx axt 0x9920 - find data/code references to this address / stt - search for stt ii - imports i - base info wx - write hex wa - write instructions t - list types t* - list obj=type pairs tf - all function signitures ts - all loaded structs ih - headers (alias for iH) idp - load pdb file * get service processor ip sudo ipmitool lan print * kerberos check cache expiration date klist -c /tmp/krb5cc_1000 * bacula get jobs sudo bacula_jobs --host myhost --set myhome * connecting to rdp xfreerdp -u myusername 10.10.10.1 * measure performance program perf stat perf stat -d #detailed * listing all currently known events: perf list * shuffle/output 30 random lines from a file shuf -n 30 words3 * check what uses a folder fuser -mv /home/martin/ * convert a lot of images to another format mogrify -format png -resize 155x238 *.svg * ruby liquid match irb require 'liquid' t = Liquid::Template.parse("{{ url }}") t.render({"data"=> [{ "id"=>4, "url"=> "example.com", "active"=> true}]}) * pandas show all rows import pandas pandas.set_option('display.max_rows', None) * clean jpeg jhead -purejpg example.jpg * linux - video recording SimpleScreenRecorder * linux - video editing OpenShot * linux - lock screen xscreensaver-command -lock * linux - get X11 coords over time watch 'xdotool getmouselocation' * linux - change X11 window screen size xdotool search --name "Mozilla Firefox" windowsize 1920 1080 * youtube-dl choose quality youtube-dl -F 'url' youtube-dl -f 'url' * turn off shell echoing stty -echo * random password dd if=/dev/urandom bs=10 count=4 | base64 * cut -f';' -d1 with keeping delimiter at the end awk 'BEGIN{FS=OFS=";"}//{print $1OFS}' alters.txt * get octal permissions for a file stat -c "%a %n" file * print registry trees in powershell $64bit_settings_regpath = Get-ChildItem -Path HKLM:\SOFTWARE\ODBC\ODBC.INI -Recurse | out-string $32bit_settings_regpath = Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\ODBC\ODBC.INI -Recurse | out-string * categorize in Outlook CTRL+F2 * ansible run notebook ansible-playbook -i hosts -K playbook.yml * tear git repository git filter-branch --subdirectory-filter src/ -- master * format qcow image to ext4 sudo virt-format --filesystem=ext4 -a android.img * DNS list all whois example.com * goaccess open file goaccess -m /tmp.log * check battery status upower -i /org/freedesktop/UPower/devices/battery_BAT0 * hugo highlight code {{< highlight go >}} A bunch of code here {{< /highlight >}} * hugo cutoff for summary * gitlab merge when pipeline succeeds git config --global alias.mwps "push -o merge_request.create -o merge_request.target=master -o merge_request.merge_when_pipeline_succeeds" * python shebang #!/usr/bin/env python3 * prince make pdf with custom css file prince -s style.css myfile.html * ffmpeg convert a bunch of pictures to video ffmpeg -pattern_type glob -i '*.png' -c:v libx264 -vf fps=25 -pix_fmt yuv420p ../out.mp4 * ffmpeg weird resolution ffmpeg -i pp1.webm -vf "scale='bitand(oh*dar,65534)':'min(720,ih)'" pp1.mp4 * ffmpeg take a snippet from a video ffmpeg -ss 00:11:07 -i -t 00:00:20 -async 1 -strict -2 * ffmpeg loseless screen grab, conv after ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1366x768 -i :0.0 -qscale 0.0001 -vcodec huffyuv -acodec libmp3lame grab.avi ffmpeg -i grab.avi output.webm * ffmpeg convert folder of webms to mp4 for f in *.webm; do ffmpeg -i "$f" -acodec libmp3lame -ar 22050 "conv/$f.mp4" done * ffmpeg lossy screen grab ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1366x768 -i :0.0 -threads 4 -y 1.webm * regex replace each letter with a symbol in regex \w -> . replaces all letters with dots * misc fglrx dependencies debhelper dh-modaliases execstack dpkg-dev dpkg-dev dkms xserver-xorg-dev (only 64 bit - lib32gcc1) * misc manipulating structured text data https://github.com/dbohdan/structured-text-tools * misc firefox "cannot read profile" fix sudo chown -R user:user .cache/mozilla/ * misc scan gmail for free stuff giveaway category:promotions free category:promotions