Search
Notion
CMD
Replace line with capture group (sed):
sed -Ei 's/(^Serv[Aa-Zz]+)=.*/\1=1.2.3.4,5.6.7.8/g' /etc/zabbix/zabbix_agentd.conf
Bash
Multi-threaded (-p N) archivation process (w/o rsync):
tar cf - /var/lib/mysql |pigz -9 -p 8 > /media/disk1/mysql.tar.gz
Bash
Grep an EXACT word:
grep -w pattern
Bash
Print number of processes for user:
ps h -Led -o user | sort | uniq -c | sort -n
Bash
Determine exact process start time:
ps -eo pid,lstart,cmd |grep [j]ava.*className
Bash
Print PIDs of the processes by multiple search patterns (-a to print full process info ):
pgrep -u userName -f 'java.*63(79|80|81|82)'
Bash
Create ext4 filesystem without reserved blocks (-m option):
mkfs.ext4 -m 0 /dev/sdd1
Bash
Resize partition and it's filesystem:
growpart /dev/sda 1 resize2fs /dev/sda1
Bash
Create single-shot task to kill multiple processes at specific time:
echo "sleep 50 ; pkill -f 'java.*63(81|82)'" | sudo at $(date +%H:%M -d "+1 min")
Bash
Take mysqldump of particular database to get SCHEMA ONLY:
mysqldump -h HOST -u USR -p PASSWD DATABASE \ --single-transaction \ --column-statistics=0 \ --skip-triggers \ --set-gtid-purged=OFF \ --default-character-set=utf8 \ --no-data \ --result-file schema.sql
Bash
SCP with public key auth:
scp -i ~/.ssh/id_rsa username@12.34.56.78:/remote/path ./
Bash
Run command 3000 times, maximum 500 in parallel:
seq 1 3000 |xargs -I % -n1 -P500 command
Bash
Change time command output format:
TIMEFORMAT='%1lR'; time command
Bash
Compare file sizes:
find ./ -type f -printf '%f %p\n' |xargs -l sh -c 'echo `wc -c ${1}` `wc -c $(find /dir1/ /dir2/ -type f -name "${0}")`' |awk '$1 == $3 {print $2,$4}'
Bash
Check disk io statistics interactive:
iostat -x sda 2
Bash
Test disk for read io limit:
hdparm -tT /dev/sda
Bash
Show disk io-heavy tasks:
iotop -o
Bash
Get GitLab project release tarball URL:
curl -s --header "PRIVATE-TOKEN: *****" "https://gitlab.example.com/api/v4/projects/138/releases/2.1.2" \ |jq -r '.assets.sources[] | select(.format == "tar.gz") | .url'
Bash
Load module on system boot:
touch /etc/modules-load.d/bt.conf echo 'btusb' > /etc/modules-load.d/bt.conf
Bash
Python: create and activate/deactivate virtualenv:
virtualenv --python=/usr/bin/python2.7 .venv source .venv/bin/activate deactivate
Bash
Print bash history with timestamp:
HISTTIMEFORMAT='%F %T ' history
Bash
Clear VM cached & buffered RAM:
echo 3 | sudo tee /proc/sys/vm/drop_caches
Bash
Run nohup without nohup.out:
nohup CMD >/dev/null 2>&1
Bash
Exclude a directory from the find search:
find . -path ./path-to-exclude -prune -o
Bash
Get SSL certificate dates from URL:
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates # -text key for more info
Bash
Convert (scale) multiple images:
find . -maxdepth 1 -iname "*.jpg" | xargs -L1 -I{} convert -resize 50% "{}" resized/"{}"
Bash