Skip to content

Instantly share code, notes, and snippets.

@prasanthkothuri
Last active July 13, 2022 19:28
Show Gist options
  • Save prasanthkothuri/f7e7d779b718345984007ab073c842fb to your computer and use it in GitHub Desktop.
Save prasanthkothuri/f7e7d779b718345984007ab073c842fb to your computer and use it in GitHub Desktop.

find all large files in the root filesystem

find / -xdev -type f -size +100M
OR
find / -xdev -type f -size +100M -exec ls -la {} \; | sort -nk 5
OR
find / -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n50

install netstat on centos 7

yum -y install net-tools

list iptables rules

iptables --list -n
ip6tables --list -n

list open sockets of a pid

lsof -p {pid} | egrep 'TCP|UDP'

tcpdump of source / destination

tcpdump -i {interface_name} -vvv | grep {destination_host}

port check with netcat

nc -4zv {ipv4_address} 22
nc -6zv {ipv6_address} 22

process with swap usage in decending order

for file in /proc/*/status ; do awk '/VmSwap|Name|\yPid\y/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 3 -n -r | less

find all block devices

lsblk
ls -l /dev /dev/mapper |grep '^b'

list all hardware

lshw -short

syntax check the script without running

bash -n {scriptname}

split file

split -l 15000 file_name new_file_name -da 2

deleting file held by a process

lsof +L1; cd /proc/{pid}/fd; ls -l |grep deleted; >{file_descriptor}

long running task

screen -S my_screen
Ctrl+a d
screen -ls
screen -r my_screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment