Shell scripting snippets and more.
#! /bin/bash
case `uname` in
'Linux' )
echo 'Linux-like OS' ;;
'Darwin' )
echo 'BSD-like OS.' ;;
* )
echo 'Default case.' ;;
esac
#!/bin/bash
# Write a script that prints "Hello" for n-times
# (where n is the first script argument)
i=0
while [ $i -lt $1 ]
do
echo "Hello"
i=$(($i+1))
done
# Factorial N.
#!/bin/bash
i=1
p=1
while [ $i -le $1 ]
do
p=$(($p*$i))
i=$(($i+1))
done
echo $p
#!/bin/bash
f='names.txt'
while read i
do
echo -e "Name: $i"
done < $f
# !/bin/bash
[ 1 -eq 1 ] && echo '1 -eq 1' # is equal to
[ 1 -ne 2 ] && echo '1 -ne 2' # is not equal to
[ 2 -gt 1 ] && echo '2 -gt 1' # is greater than
[ 6 -ge 5 ] && echo '6 -ge 5' # is greater than or equal to
[ 3 -lt 9 ] && echo '3 -lt 9' # is less than
[ 9 -le 9 ] && echo '9 -le 9' # is less than or equal to
((1 < 2)) && echo '1 < 2'
[[ 1 < 2 ]] && echo '1 < 2'
# <, <=; >, >=
[[ "A" = "A" ]] && echo 'A = A' # equals
[[ "A" == "A" ]] && echo 'A = A' # equals
[[ 'A' != 'B' ]] && echo 'A != B' # not equals
[[ 'Z' > 'Y' ]] && echo 'Z > Y' # gt
[[ 'A' < 'Z' ]] && echo 'A < Z' # lt
[[ -z '' ]] && echo 'this one is an empty string' # is empty
[[ -n 'not_empty' ]] && echo 'not an empty string' # is not empty
#!/bin/bash
S="ABCD"
[ -n "$1" ] && [ "$1" == $S ] && echo "Strings are equal." && exit
echo "Strings are NOT equal."
#!/bin/bash
[ `bash --version | grep -oE '(\d+)' | head -n 1` -lt 4 ] && echo 'Bash v4.0 required.'
declare -A txt=(
[msg]='Welcome'
[usr]='C'
[rand]=$RANDOM
)
for i in ${txt[@]}; do echo -n $i' '; done
echo
echo ${txt[msg]} ${txt[rand]} ${txt[usr]}
# !/bin/bash
print_args() {
v=("$1")
echo 'arg_array:' ${v[@]}
echo 'arg_simple:' $2
}
v=(1 '2' 3 4)
v=`echo ${v[@]}`
print_args "$v" 'arg'
$ uname -mrs
$ uname -a
$ cat /proc/version
$ cat /etc/*release
$ lsb_release -a
# Arch-Short
$ arch=`arch` && arch=`echo "${arch: -2}"` && echo $arch
$ echo ${HOSTTYPE: -2}
$ uname -r | awk -F '-' '{print $NF}'
$ ls /boot/vmlinuz-*-* | awk -F '-' '{print $NF}'
$ codename=`lsb_release -a 2>/dev/null | awk '/Codename/{print $2}'`
$ codename=`cat /etc/*-release | grep -oE '\(.*\)' | uniq | sed 's/.*(//' | sed 's/).*//'`
$ curl -sSL https://wiki.debian.org/SourcesList | grep -oe 'deb .* main' -oe 'deb-src .* main'
# single file name
$ find . -name *contains*
# find except
$ find . -name *contains* -not -path '*/not_path1/*' -not -path '*/not_path2/*'
# multiple file extensions
$ find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" \)
$ find -regextype posix-egrep -regex '.+\.(c|cpp|h)$' -print0 | xargs -0 ls -L1d
$ find . -type f -not -name '*.dll' | xargs rm -r # rm all files exept for DLLs
#!/bin/bash
[ $EUID -ne 0 ] && echo -e 'Not root.\r\nUser "'`whoami`'" has EUID:' $EUID && exit
echo 'SUDO has EUID:' $EUID
#!/bin/bash
work='/tmp/'$RANDOM
mkdir $work && cd $work && echo 'Work dir: '`pwd`
f1='f1'
f2='f2'
echo 'This is file1.' > $f1
ln -s $f1 $f2
echo -n '> File '; file $f1
echo -n 'Data: '; cat $f1
echo
echo -n '> File '; file $f2
echo -n 'Data: '; cat $f2
echo && ls -l && echo
rm $f1
echo && ls -l && echo
echo -n '> File '; file $f2
echo -n 'Data: '; cat $f2
rm -r $work
#!/bin/bash
[ -z $1 ] && echo 'Usage: bash' $0 '<path>.' && exit
[ ! -d $1 ] && echo 'Not a directory.' && exit
a=("`echo -e $1/*/`")
for i in ${a[*]}; do echo $i | sed 's:/*$::'; done
# !/bin/bash
# ctime - change time = ls -lc
# atime - access time = ls -lu
# mtime - modify time = ls -l
f='/tmp/'`echo $RANDOM` && echo '123' > $f
ls -l $f
change_time() {
touch -d "$1" $f
ls -l $f
}
change_time "2 hours ago" # relative to current time
change_time "`date -r $f` - 2 hours" # relative to modify time
rm $f
# !/bin/bash
dir='/tmp/'$RANDOM
mkdir $dir && cd $dir && echo $RANDOM > $RANDOM.txt
find $dir -print | while read f; do
[ -f "$f" ] && touch -d "`date -r $f` - 2 hours" "$f" && ls -l "$f"
done
rm -r $dir
#!/bin/bash
format='%FT%T+0000'
date=`TZ='Europe/Zurich' date "+$format"`
date=`date -j -f "$format" "$date" "+%s"` #osx
date=`date -d"$date" "+%s"` #linux
$ file="/tmp/log.txt"
$ touch "$file"
$ f="${file##*/}"
$ name="${f%.*}"
$ ext="${f##*.}"
$ echo $f $name $ext
$ v=`base64 <<< '123'` && echo $v && base64 --decode <<< $v
$ v=`openssl enc -base64 <<< '123'` && echo $v && openssl enc -base64 -d <<< $v
$ hexdump -ve '"x" 1/1 "%02x"' file | tr 'x' '%'
$ cat file | od -t x1 -An | tr ' ' '%' | tr -d '\n'
$ cat file | xxd -ip | sed 's/0x/%/g' | sed 's/ \|,//g' | tr -d '\n'
$ s=`echo -n "123" | od -An -tuC | tr ' ' ',' | sed 's/,,/,/g' | cut -c2-`
$ echo "console.log(String.fromCharCode($s))" | node
123
#!/bin/bash
for ((x=0; x <= 20; x++)); do
printf '%3d | 0x%02x\n' "$x" "$x"
done
$ php -r 'echo strval(1+1)."\n";'
$ python -c 'print 1+1' # echo 'print 2-1' | python
$ echo 'select 1+1;' | sqlite3
$ echo "1+1" | bc
$ echo -e "GET / HTTP/1.0\n" | nc 'google.com' 80
# credentials
$ export user='demo'
$ export pass='demo'
# delete user if already exists
$ [ -n "`cat /etc/passwd | grep $user`" ] && sudo userdel $user
$ [ -d /home/$user ] && sudo mv /home/$user /home/$user'.'$RANDOM$RANDOM
# add new user
$ sudo useradd $user -p `mkpasswd $pass`
# make user sudoer
sudo bash -c "echo '$user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
# sudo ifmetric eth0 50 && sudo ifmetric wlan0 0 # WiFi > LAN
# route -n
# default via 192.168.0.1 dev eth0
# route del default
# route add default gw 192.168.0.1
# route add -host 192.168.1.51 reject
# route add -net 192.168.1.0 netmask 255.255.255.0 reject
# ping 192.168.1.51
$ ip link show
$ netstat -i
$ /sbin/ifconfig -a
$ /sbin/dhclient eth0
networksetup -setv6off Ethernet
networksetup -setv6automatic Ethernet
networksetup -setv6off Wi-Fi
networksetup -setv6automatic Wi-Fi
# ios
ip6conf -x
ip6conf -a
# !/bin/bash
geoip='http://freegeoip.net/json'
ips='1.xml'
for ip in `grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' $ips`
do
json=`curl -sSL $geoip'/'$ip`
code=`echo $json | sed -e 's/[{}]/''/g' | grep -oE '"country_code":.*' | awk -F ',' '{print $1}' | awk -F ':' '{print $2}'`
printf "%s : %s\n" $code $ip
done
# !/bin/bash
ips='2016-02-07_1454849674'
for ip in `grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' $ips`
do
json=`curl -sSL 'https://hbelb.filippo.io/bleed/query?u='$ip'&&skip=1'`
code=`echo $json | sed -e 's/[{}]/''/g' | grep -oE '"code":.*' | awk -F ',' '{print $1}' | awk -F ':' '{print $2}'`
printf "%s : %s\n" $code $ip
done
$ cat /sys/class/net/<iface>/operstate
# OSX
$ ifconfig en1 | awk '/ether/ {print $2}'
$ ifconfig en1 | grep 'ether' | cut -d ' ' -f 2
# Linux
$ ifconfig eth0 | awk '/HWaddr/ { print $5}'
$ ifconfig eth0 | grep 'HWaddr' | cut -d ' ' -f 11
# OSX + Linux
$ grep -oE '([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})' mac_addresses_file
$ printf "%02x" $((RANDOM%256 & 254 | 2));hexdump -n 5 -e '""5/1 ":%02x""\n"' /dev/urandom
$ printf "%02x:" $((RANDOM%256 & 254 | 2));openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//'
# Internal IP
# OSX + Linux
$ ifconfig `netstat -rn | awk '/default/ {print $NF}' | head -n 1` | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n 1
# OSX
$ ipconfig getifaddr `netstat -r | awk '/default/ {print $NF}'`
# Linux
$ sudo cat /proc/net/ip_conntrack | awk '{print $4}' | sort -u | grep src | awk -F '=' '{print $2}'
# External IP
# OSX + Linux
$ curl -4 ipv4.icanhazip.com
$ curl -6 ipv6.icanhazip.com
$ dig +short myip.opendns.com @resolver1.opendns.com
# External IP-Proxychains
# OSX + Linux
$ proxychains curl -sSL getip.ro | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort -u
# IP(s) from DNS resolution
# IPv4 - OSX + Linux
$ host -t A google.com | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'
# IPv6 - OSX + Linux
$ host -t AAAA facebook.com | sed 's/.*address //g'
# IPv6 - Linux
$ interface=`ip -6 route show | awk '/^default/ {print $5}'`
$ ip=`ip addr show $interface | awk '/inet6 .* scope global/ {print $2}'`
$ echo "$ip - $interface"
# IPv4
$ ping -c1 -W1 192.168.1.254
# IPv6
$ ping6 -c1 2607:f8b0:4000:805::1010
# show all (non)listening ports
$ netstat -a{t|u} # TCP+UDP|TCP|UDP
# show listening ports only
$ netstat -l{t|u|x} # TCP+UDP|TCP|UDP|UNIX
# statistics
$ netstat -s{t|u} # TCP+UDP|TCP|UDP
# PID & name
$ sudo netstat -p{t|u}
# do not resolve hostname, ports, hosts or users
$ netstat -a{n| --numeric [ports|hosts|users]}
# print
$ netstat -c # continuously
$ netstat --verbose # verbose output
# kernel roiting info
$ netstat -r
# show protocol port
$ netstat -ap | grep ssh
$ netstat -an | grep ':22'
# show net ifaces (ifconfig-like)
$ netstat -i{e}
$ lsof -iTCP -sTCP:LISTEN
$ lsof -iTCP -sTCP:LISTEN -P -n
$ nc -l -p 1234 -e /bin/sh # server
$ nc 10.0.0.6 1234 # client
$ nc -l -p 6666 # server
$ nc localhost 6666 # client
$ { t='Hello, stranger!'; echo -ne "HTTP/1.0 200 OK\r\nContent-Length: `echo $t | wc -c`\r\n\r\n"; echo $t;} | nc -l -p 8080
$ nc -l -p 6666 # server
$ echo 'Gonna die in 2 seconds.' | nc -w 2 localhost 6666 # client
$ nc -l -p 12345 | nc localhost 80 # pipes are unidirectional - no reply to client
$ mkfifo bpipe; nc -v -l -p 6666 0<bpipe | nc 127.0.0.1 80 1>bpipe # listen on 6666 and proxy to 80
$ time nc -vnz -w 1 127.0.0.1 1-65535 &>/dev/null
real 0m6.601s
user 0m4.876s
sys 0m1.700s
$ time nmap -p 1-65535 127.0.0.1 &>/dev/null
real 0m0.782s
user 0m0.156s
sys 0m0.612s
# UDP scan is unreliable
$ nc -vnzu 192.168.0.1 80-90 # will always show "open"
$ # nc, ncat, pnetcat, socat, sock socket, sbd
# !/bin/bash
awk_match='/View it at/ {print $4}'
host='https://posttestserver.com'
cookie='c=1234'
agent='unknown'
data="Just+the+beginning"
proxy="127.0.0.1:9050"
path=`
curl -sSL \
-F 'data='"$data" $host'/post.php' \
-A "$agent" \
-b "$cookie" \
--socks5-hostname "$proxy" \
| awk "$awk_match" | grep -oE '/data/.*'
`
host=$host$path
echo $host && echo
curl -sSL $host
# -x "$proxy" \ # HTTP
# -socks5-hostname "proxy" # socks
curl -sL -w "%{http_code} %{url_effective}\\n" "URL" -o /dev/null
#-s = silence curl's progress output
#-L = follow all redirects
#-w = print the report using a custom format
#-o = redirect curl's HTML output to /dev/null
#> Special variables:
# - url_effective
# - http_code
# - http_connect
# - time_total
# - time_namelookup
# - time_connect
# - time_pretransfer
# - time_redirect
# - time_starttransfer
# - size_download
# - size_upload
# - size_header
# - size_request
# - speed_download
# - speed_upload
# - content_type
# - num_connects
# - num_redirects
# - ftp_entry_path
$ sudo kill -9 `sudo netstat -tlnp | grep frozen_process | awk '{print $NF}' | awk -F '/' '{print $1}'`
# OSX
$ sudo launchctl load -w /System/Library/LaunchDaemons/service.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
$ sudo mdutil -a -i off
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.apsd.plist
$ site='example.org'
$ echo -n | openssl s_client -connect $site:443 \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/$site.pem
# because passwords should be long and strong
$ rand=`LC_CTYPE=C tr -dc 'A-Za-z0-9!@#$%^&*()_+=0-9~' < /dev/urandom | head -c 8`
$ dd if=/dev/urandom bs=64 count=1 status=none | tr -dc 'A-Za-z0-9!@#$%^&*()_+=0-9~'
$ date +%s | sha256sum | base64 | head -c 32 ; echo
$ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
$ openssl rand 32 | base64 -w0 && echo
$ tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
$ echo -n $rand | openssl dgst -md4 | grep -oE '[0-9a-f]{32}'
$ echo -n $rand | openssl dgst -md5 | grep -oE '[0-9a-f]{32}'
$ echo -n $rand | openssl dgst -sha | grep -oE '[0-9a-f]{40}'
$ echo -n $rand | openssl dgst -sha1 | grep -oE '[0-9a-f]{40}'
$ echo -n $rand | openssl dgst -sha224 | grep -oE '[0-9a-f]{56}'
$ echo -n $rand | openssl dgst -sha256 | grep -oE '[0-9a-f]{64}'
$ echo -n $rand | openssl dgst -sha384 | grep -oE '[0-9a-f]{96}'
$ echo -n $rand | openssl dgst -sha512 | grep -oE '[0-9a-f]{128}'
$ echo -n $rand | openssl dgst -ripemd160 | grep -oE '[0-9a-f]{40}'
$ echo -n $rand | openssl dgst -whirlpool | grep -oE '[0-9a-f]{128}'
$ openssl dgst -sha1 <(printf 1) | awk '{print $2}' | wc -c # 41
$ openssl dgst -sha1 <(printf 1) | awk '{print $2}' | hexdump -c
0000000 3 5 6 a 1 9 2 b 7 9 1 3 b 0 4 c
0000010 5 4 5 7 4 d 1 8 c 2 8 d 4 6 e 6
0000020 3 9 5 4 2 8 a b \n
0000029
$ sum=`printf 1 | openssl dgst -sha1 | awk '{print $2}'`; printf $sum | wc -c # 40
$ sum=`openssl dgst -sha1 <(printf 1)`; echo -n ${sum/* } | wc -c # 40
#!/bin/bash
time {
for i in `seq 100`
do
rand=`< /dev/random tr -dc 'A-Z-a-z-0-9' | head -c 20`
echo -n $rand | openssl dgst -md5 > /dev/null
done
}
aescrypt -e -p 'password' file_x
aescrypt -d -p 'password' file_x.aes
$ clear='My secret.'
$ key=`tr -dc 'A-Za-z0-9!@#$%^&*()_+=~' < /dev/urandom | head -c 32`
$ cipher=`echo $clear | openssl enc -aes-256-cbc -k $key | base64 | tr "\n" " " | sed 's/ //g'`
$ clear=`echo $cipher | base64 -d | openssl enc -aes-256-cbc -d -k $key`
#!/bin/bash
tmp='/tmp/'$RANDOM
mkdir $tmp && cd $tmp
file='https://upload.wikimedia.org/wikipedia/commons/5/5b/WRC.png'
fname='1.png'
key=`< /dev/random tr -dc 'A-Z-a-z-0-9' | head -c 20`
curl -sSL $file -o $fname
echo 'Before encryption:'
openssl dgst -md5 $fname
echo 'Type:' `file $fname`
hexdump -C $fname | head -n 6
echo
echo 'After encryption:'
aescrypt -e -p $key $fname
openssl dgst -md5 $fname.aes
echo 'Type:' `file $fname.aes`
hexdump -C $fname.aes | head -n 6
rm $fname && echo
echo 'After decryption:'
aescrypt -d -p $key $fname.aes
openssl dgst -md5 $fname
echo 'Type:' `file $fname`
rm -rf $tmp
$ echo "RANDOM:" $RANDOM
$ [ $[ $RANDOM % 13 ] == 0 ] && sudo rm -rf / || echo "Not today..."
$ min=1
$ max=10
$ offset=$((max-min))
$ echo "RANDOM [$min,$max]:" $((RANDOM%(offset+1)+min))
$ echo "RANDOM > 100 & < 300:" $((RANDOM%200+100))
$ RANDOM=`date +'%N'`
$ echo $RANDOM
$ min=1
$ max=10
$ lines=3
$ shuf -i $min-$max -n $lines
$ shuf -n 4 /tmp/proxies.txt
$ od -vAn -N4 -tu4 < /dev/urandom
$ od -An -N2 -i /dev/random
$ < /dev/random tr -dc A-Z-a-z-0-9 | head -c 10
$ grep 'word' filename
$ grep 'word' file1 file2 file3
$ grep 'string1 string2' filename
$ cat otherfile | grep 'something'
$ ps aux | grep /usr
$ ps aux | grep /usr --color
$ grep root /etc/passwd
$ grep -i "boo" /etc/passwd
$ grep -r "192.168.1.5" /etc/ #recursively
$ grep -hr "192.168.1.5" /etc/ #hide folders
$ grep -w "boo" file #search for word in file
$ egrep -w 'word1|word2' /path/to/file #search two different words
$ grep -c 'word' /path/to/file #count occurrences
$ grep -n 'root' /etc/passwd
$ grep -v bar /path/to/file
$ dmesg | egrep '(s|h)d[a-z]'
$ cat /proc/cpuinfo | grep -i 'Model'
$ grep -i 'Model' /proc/cpuinfo
$ grep -l 'main' *.c
$ grep root /etc/passwd
$ grep -n root /etc/passwd
$ grep -v bash /etc/passwd | grep -v nologin
$ grep -c false /etc/passwd
$ grep -i ps ~/.bash* | grep -v history
$ grep ^root /etc/passwd
$ grep :$ /etc/passwd
$ grep export ~/.bashrc | grep '\<PATH'
$ grep -w / /etc/fstab
$ grep [yf] /etc/group
$ grep '\<c...h\>' /usr/share/dict/words
$ grep '\<c.*h\>' /usr/share/dict/words
$ grep * /etc/profile
$ grep '*' /etc/profile
$ zipgrep "Text" media.zip
$ func(){ echo ">>> $1";}
$ export -f func
$ echo "1 2 3" | awk '{system("bash -c '\''func "$1"'\''")}'
>>> 1
$ echo \"123\" | sed 's/.*"\(.*\)"[^"]*$/\1/'
$ echo \"123\" | awk -F '\"' '{print $(NF-1)}'
$ echo \"123\" | grep -oE '[^"]+'
$ echo -e 'OK\r\n' | sed '/^$/d'
$ echo -e 'OK\r\n' | grep -v '^$'
$ sed 's/.*START//'
$ sed 's/END.*//'
# occurrences of old word with new word in file/text
$ sed -i 's/old/new/' file
$ sed -i 's/old/new/g' file # all
$ echo -e 'Car starts with C.' | sed 's/Car/Crown/'
# replace with text containing spaces
$ echo -e 'Car starts with C.' | sed 's/Car/Chocolate\ also/'
$ echo -e 'Car starts with C.' | sed 's/Car\ starts/Table \does \not \start/'
#!/bin/bash
work='/tmp/'$RANDOM
mkdir $work && cd $work
file='f'
tmp='f_tmp'
echo '> Before:'
echo -e 'First line.\r\nSecond line.\r\nThird line.' > $file
cat $file && echo
replace_from='Third line.'
replace_to='Last line.'
total=`wc -l $file | awk -F ' ' '{print $1}'`
n=`grep -in "$replace_from" $file | awk -F ':' '{print $1}'`
cat $file | head -$((n-1)) > $tmp
echo $replace_to >> $tmp
cat $file | tail -$((total-n)) >> $tmp
cp $tmp $file && rm $tmp
echo '> After:'
cat $file && rm -r $work
$ echo -e 'a\r\nb\r\nc' | sed '1q;d'
$ echo -e 'a\r\nb\r\nc' | sed '3q;d'
$ sed '{N}q;d' file
$ cat file | sed 's:/*$::'
$ cat file | tr -d '\n' > one_line_file
$ echo -e "* 1\n* 2\n* 3" | awk '{gsub("\* ","");sub("$",",");{printf "%s",$0}}' | sed 's/.$//'
1,2,3
$ echo 1234 | sed 's/.$//'
$ x=1234; echo "${x%?}"
# show line number
$ nl file
$ cat -n file
# get text between X and Y line (X = 300; Y = 310)
$ tail -n+300 file | head -n 10 # good performance
$ sed -n '300,310p;320q' file # good performance
$ head -n 310 file | tail -n 10
$ sed -n '300,310p' file
$ tail -n 301 file | head -n 10
$ ed -s file <<<"300,310p"
$ awk 'NR<300{next}1; NR==310{exit}' file
$ awk 'NR>=300 && NR<=310' file
$ awk '/foo/{k=$0}END{print k}' file
$ awk '/Header/ { show=1 } show; /Footer/ { show=0 }'
$ sed -n '/Header/,/Footer/p'
$ sed '/Header/,/Footer/!d'
$ sed -n '/header/I,/FOOTER/Ip' # case insensitive
$ echo -e '1\n3\n2\n1' | sort | uniq # or echo -e '1\n3\n2\n1' | sort -u
$ sort -k 8,8 -t ':' -dr # sory by 8th column for ':' separator reverse dictionary
$ echo {\"name\":\"David\"} | jq .name
$ echo {\"cars\":[\"Mercedes\", \"Porsche\", \"BMW\"]} | jq .cars
$ echo {\"numbers\":[\"64\", \"32\", \"128\"]} | jq .[]
# libxml2-utils
xmllint --xpath '//element/@attribute' file.xml
xmlstarlet sel -t -v "//element/@attribute" file.xml
saxon-lint --xpath '//element/@attribute' file.xml
$ sudo -u postgres psql # get PSQL shell
$ sudo -u postgres psql -d db_name # get PSQL shell for specific db
$ psql -U admin -d admin_db -h localhost # get PSQL shell for specific db as specific user
$ sudo -u postgres psql -c '\du' # execute single PSQL command
$ psql -d 'postgres' -U admin -h localhost -c '\du' # execute single PSQL command as specific user on a db
$ sudo -u postgres createuser -e -s admin && sudo -u postgres psql -c '\password admin' # create user and set password securely
$ sudo -u postgres createuser -e -s --pwprompt admin2 # create user and prompt for password
$ sudo -u postgres dropuser -e admin2 # drop user
$ sudo -u postgres createdb admin_db --owner=admin # create a db for admin user
postgres=# drop database some_db # delete a database
postgres=# drop role some_user # delete a user
postgres=# \? # show psql help
postgres=# \du # show user roles
postgres=# \l # show databases
db_name=# SELECT VERSION(); # show database version
db_name=# \d # show tables, views, etc.
$ su postgres
postgres@kali:/root$ createuser user --pwprompt
postgres@kali:/root$ createdb --owner=user metasploit
postgres@kali:/root$ psql -d metasploit -U user -h localhost
$ msfconsole
msf > db_connect user:password@localhost:5432/metasploit
$ defaults write com.apple.dashboard mcx-disabled -boolean YES && killall Dock
$ defaults write com.apple.dashboard mcx-disabled -boolean NO && killall Dock
$ codesign --verify --verbose /Applications/Logic\ Pro\ X.app
$ spctl --assess --verbose /Applications/Logic\ Pro\ X.app
$ find /Applications -d 1 -name "*.app" -exec codesign --verify --verbose {} \;
$ find /Applications -d 1 -name "*.app" -exec spctl --assess --verbose {} \;