Difference between revisions of "Shell Tricks"

From Athenaeum
Jump to: navigation, search
(Random)
(Random)
Line 3: Line 3:
  
 
=Random=
 
=Random=
 +
Get certs and other TLS info
 +
<pre>openssl s_client -connect nextcloud.racklinux.net:443 -servername nextcloud.racklinux.net -showcerts</pre>
  
 
Kill all of something
 
Kill all of something

Revision as of 23:51, 9 February 2019


Random

Get certs and other TLS info

openssl s_client -connect nextcloud.racklinux.net:443 -servername nextcloud.racklinux.net -showcerts

Kill all of something

ps aux | grep prog_name | awk '{print $2}' | xargs kill -9

Create/Restore a compressed dd image of a disk

dd status=progress if=/dev/sde conv=sync,noerror bs=64K | gzip -c  > /storage_loc/file_name.img.gz
zcat /storage_loc/file_name.img.gz | dd status=progress of=/dev/sde

Get the round trip time of a website (in seconds):

curl -s -w "%{time_total}\n" -o /dev/null http://www.google.com

Find and remove:

find ./ -name *.m3u -exec rm -v {} +

Compare two directory trees:

find directory1 -type d -printf "%P\n" | sort > file1
find directory2 -type d -printf "%P\n" | sort | diff - file1

In the following command any output (STDOUT AND STDERR) is piped to the next command. This works well with tee because then your log will have both types of output just like your shell window. This has been tested in tcsh, but will likely work in other shells.

/run/any/command.sh |& tee log.txt

Empty a file.

: > ./file

Clear swap space and adjust swappiness

swapoff -a && echo -e "\nvm.swappiness=1" >> /etc/sysctl.conf && sysctl -p && swapon -a

Dump http headers and call (don't forget to change the port)

stdbuf -oL -eL /usr/sbin/tcpdump -A -s 10240 "tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)" | egrep -a --line-buffered ".+(GET |HTTP\/|POST )|^[A-Za-z0-9-]+: " | perl -nle 'BEGIN{$|=1} { s/.*?(GET |HTTP\/[0-9.]* |POST )/\n$1/g; print }'

Sed One Liners

Remove a line that contains a specific string

sed -i '/pattern to match/d' ./infile

If instead you'f like to use perl to delete lines that match a string

perl -i.bak -ne 'print unless m/some_pattern/' /path/to/infile

You could also use grep

grep -vP 'some_pattern' /path/to/infile

Show specific lines from a file

sed -n '20,40p' file_name