Skip to content

Instantly share code, notes, and snippets.

@behrad
Last active March 1, 2020 10:02
Show Gist options
  • Save behrad/5772680 to your computer and use it in GitHub Desktop.
Save behrad/5772680 to your computer and use it in GitHub Desktop.
Linux Commands
# File Management
#==================
tail -n +$X /path/to/file | head -n $((Y-X+1))
grep -ir -n "ramesh" *
find / -iname passwd
# Process management
#===================
lsof -p PID
cat /proc/[pid]/cmdline #process's command line
lsof -i TCP:22-90
ps -ef | more
ls -l /proc/[pid]/fd|sed -n '/socket/{s/.*\[//;s/\]//p}' #open sockets by process
netstat -np
netstat -ae #socket info
netstat -an | grep -e tcp -e udp | wc -l
ss -s
ss -tan state fin-wait-2 | wc -l
ss -tp | grep -v Recv-Q | sed -e 's/.*users:(("//' -e 's/".*$//' | sort | uniq
iostat
dtrace && strace
# Network management
#===================
ifconfig -a
ifconfig eth0 up
route add -net $NET netmask $MASK gw $GATEWAY
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -d 192.168.200.35/32 -p tcp -m tcp --dport 5065 -j DNAT --to-destination 10.102.52.1:5061
iptables -t nat -A POSTROUTING -d 10.102.52.1/32 -o eth0 -j SNAT --to-source 192.168.200.35
#iptables -A POSTROUTING -o vlan18 -j MASQUERADE
# System management
#===================
du -h --max-depth=0 *
grep Free /proc/meminfo
du -hs /path/to/folder
du --max-depth=1 /path/to/folder | sort -nk1
baobab /home/jrad
rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
rpm -ev httpd
### Linux Network Configuration
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=192.168.1.44
NETMASK=255.255.255.0
## Configure Default Gateway
#
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos6
GATEWAY=192.168.1.1
## Restart Network Interface
#
/etc/init.d/network restart
## Configure DNS Server
#
# vi /etc/resolv.conf
nameserver 8.8.8.8 # Replace with your nameserver ip
nameserver 192.168.1.1 # Replace with your nameserver ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment