Difference between revisions of "Linux cli snippets"
From DevOps Notebook
(10 intermediate revisions by the same user not shown) | |||
Line 21: | Line 21: | ||
<pre> | <pre> | ||
# openssl x509 -noout -dates -in /path/to/cert.crt | # openssl x509 -noout -dates -in /path/to/cert.crt | ||
+ | </pre> | ||
+ | |||
+ | === Check ssl expiry date from linux cli === | ||
+ | <pre> | ||
+ | # echo | openssl s_client -showcerts -servername devopsnotebook.com -connect devopsnotebook.com:443 2>/dev/null | openssl x509 -inform pem -noout -text |grep 'Not After' | ||
</pre> | </pre> | ||
Line 31: | Line 36: | ||
<pre> | <pre> | ||
# ls -l -S | sort -k 5 -n | # ls -l -S | sort -k 5 -n | ||
+ | </pre> | ||
+ | |||
+ | === Change different permissions to files and folders in one run recursively === | ||
+ | <pre> | ||
+ | # find /path/to/dir -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} + | ||
+ | </pre> | ||
+ | |||
+ | === Search and replace string in all files recursively in given folder === | ||
+ | <pre> | ||
+ | # find ./ -type f -exec sed -i -e 's/tomato/potato/g' {} \; | ||
+ | </pre> | ||
+ | |||
+ | === Destroy all partitions table and data on drive === | ||
+ | <pre> | ||
+ | # sgdisk --zap-all /dev/nvme0n1 | ||
+ | </pre> | ||
+ | |||
+ | === Push dns changes to secondary === | ||
+ | <pre> | ||
+ | # rndc retransfer domain.com | ||
+ | </pre> | ||
+ | |||
+ | === Delete 5 lines after a pattern with sed (including the line with the pattern) === | ||
+ | <pre> | ||
+ | # sed -e '/pattern/,+5d' file.txt | ||
+ | </pre> | ||
+ | === Delete 5 lines after a pattern with sed (excluding the line with the pattern) === | ||
+ | <pre> | ||
+ | # sed -e '/pattern/{n;N;N;N;N;d}' file.txt | ||
+ | </pre> | ||
+ | |||
+ | === User iperf to test real bandwidth speed === | ||
+ | <pre> | ||
+ | # iperf -s # run on first machine | ||
+ | # iperf -c <IP of server> # run on second with ip of first one | ||
+ | </pre> | ||
+ | |||
+ | === Get only first exact result from grep === | ||
+ | <pre> | ||
+ | # grep -o -a -m 1 -h -r "string" <filename.txt> | ||
</pre> | </pre> |
Latest revision as of 12:49, 14 September 2022
Contents
- 1 Linux command line snippets
- 1.1 Get website SSL certificate details using CLI
- 1.2 Temporary stop bash history
- 1.3 Check ssl expiry date on file from cli
- 1.4 Check ssl expiry date from linux cli
- 1.5 Start all vm's with autostart set with virsh
- 1.6 Sort files by size with ls
- 1.7 Change different permissions to files and folders in one run recursively
- 1.8 Search and replace string in all files recursively in given folder
- 1.9 Destroy all partitions table and data on drive
- 1.10 Push dns changes to secondary
- 1.11 Delete 5 lines after a pattern with sed (including the line with the pattern)
- 1.12 Delete 5 lines after a pattern with sed (excluding the line with the pattern)
- 1.13 User iperf to test real bandwidth speed
- 1.14 Get only first exact result from grep
Linux command line snippets
Get website SSL certificate details using CLI
$ echo | openssl s_client -showcerts -servername sendfileto.net -connect sendfileto.net:443 2>/dev/null | openssl x509 -inform pem -noout -text
Temporary stop bash history
Turn off:
$ set +o history
Turn on:
$ set -o history
Alternative is to add HISTCONTROL="ignorespace" into .bashrc file and all things written with space in front wont be recorded in history
Check ssl expiry date on file from cli
# openssl x509 -noout -dates -in /path/to/cert.crt
Check ssl expiry date from linux cli
# echo | openssl s_client -showcerts -servername devopsnotebook.com -connect devopsnotebook.com:443 2>/dev/null | openssl x509 -inform pem -noout -text |grep 'Not After'
Start all vm's with autostart set with virsh
# for i in $(virsh list --name --autostart); do virsh start $i; done
Sort files by size with ls
# ls -l -S | sort -k 5 -n
Change different permissions to files and folders in one run recursively
# find /path/to/dir -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
Search and replace string in all files recursively in given folder
# find ./ -type f -exec sed -i -e 's/tomato/potato/g' {} \;
Destroy all partitions table and data on drive
# sgdisk --zap-all /dev/nvme0n1
Push dns changes to secondary
# rndc retransfer domain.com
Delete 5 lines after a pattern with sed (including the line with the pattern)
# sed -e '/pattern/,+5d' file.txt
Delete 5 lines after a pattern with sed (excluding the line with the pattern)
# sed -e '/pattern/{n;N;N;N;N;d}' file.txt
User iperf to test real bandwidth speed
# iperf -s # run on first machine # iperf -c <IP of server> # run on second with ip of first one
Get only first exact result from grep
# grep -o -a -m 1 -h -r "string" <filename.txt>