Skip to content

Instantly share code, notes, and snippets.

@anshulkhare7
Last active July 6, 2021 06:52
Show Gist options
  • Save anshulkhare7/b832b7f456823bcfd52596168e63e4f1 to your computer and use it in GitHub Desktop.
Save anshulkhare7/b832b7f456823bcfd52596168e63e4f1 to your computer and use it in GitHub Desktop.
Linux commands cheatsheet

Renaming multiple files using regex.

E.g. here we're renaming all the files of pattern 'ABC_LTD-507685-2017.pdf to '507685-2017.pdf'

rename -v -n 's/[^-]+-(.*)/$1/g' *.pdf

Alias for finding my ip

alias public_ip='dig +short myip.opendns.com @resolver1.opendns.com'

Kill a process with a given pattern

pkill -f <pattern>

Split files and reassemble using split and cat

split -b 800M large-file.iso file_prefix_
cat file_prefix_* > reassembled-large-file.iso

Verify integrity. The checksum should be same.

md5sum large-file.iso
md5sum reassembled-large-file.iso

List files filter by size

find . -type f -size +5000c Filter files greater than 5000kb
find . -type f -size -5000c Filter files smaller than 5000kb

Show total RAM

cat /proc/meminfo

Show ports listening on this box

netstat -nltp

Show all systemctl services

systemctl --type=service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment