1) How to use specific interface(enp0s3) to connect remote host
curl -I --interface enp0s3 https://google.com
2) traceroute and tcpdump example commands
traceroute -I www.google.com
tcpdump -D - shows all interfaces
tcpdump -i eth0 src SRC_IP
tcpdump -i eth0 dst DST_IP
tcpdump -n -i eth0 port 8099
curl -v http://183.82.106.240:8099
tcpdump -n -i eth0 port 8099 -c 10
tcpdump -n -i eth0 -w /home/naveen/tcpdump.pcap
3) How to check VM is connected with internet or not from command line
curl -I https://www.google.com/
if you get HTTP/1.1 200 OK , then internet is working
4) How to find the large size of file in current directory
find . -type f -exec du -Sh {} + | sort -rh | head -n 10
5) find the 10 largest directories in current /
find / /proc -prune -type d -print0 | xargs -0 du 2>/dev/null | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh 2>/dev/null {}
6) find the 10 largest files in /
find / -path /proc -prune -o -type f -print0 | xargs -0 du 2>/dev/null | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh 2>/dev/null {}
du -shx ==> exclude the directories
7) SAR Handy Commands
sar -u -f sa05 ==> CPU Statictics ( sar -u -f sa05 | sort -k7 -n ==> print output sort wise by 7th column with numeric)
sar -r -f sa05 ==> Memory ( sar -r -f sa05 | sort -k5 -n)
sar -b -f sa05 ==> I/O Statictics
sar -p -d -f sa03 ==> Disk Statictics
sar -r -n DEV -f sa03 ==> Ethernet Statictics
sar -n DEV --iface=eth0 ( shows current VM ethernet staticstics)
sar -n EDEV --iface=eth0
For More : https://alltechguru99.blogspot.com/2020/10/how-to-check-cpu-memory-utilization-at.html
8) lsof - list of open files Handy Commands
a) shows list of open top consumed 15 files ( non customize format)
lsof / | sort -r -s -n -k 7 | head -15
b) shows list of open top consumed deleted 15 files ( non customize format)
lsof / | sort -r -s -n -k 7 | head -15 | grep -i deleted ==> this one good
lsof / | grep -i deleted | sort -r -s -n -k 7 | head -15
c) shows list of open top consumed 15 files along with pid and user ( customize - Print output in MB format)
lsof / | awk '{if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 " " $2 " " $3}' | sort -nu | tail -n15
d) shows list of open top consumed deleted 15 files with pid and user ( customize - Print output in MB format)
lsof / | grep -i deleted | awk '{if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 " " $2 " " $3}' | sort -nu | tail -n15
Note: By default output shows in BYTES , so we can convert to MB by dividing
1 Mebibytes = 1048576 Bytes
9) Command Info
nfs - no_root_squash
Treat the remote root user as local root — If this option is on, it enables the remote root user host accessing your shared directory to save and modify files as though he or she were the local root user.
Having this on is a security risk, since the remote user can potentially modify critical files. (This sets the no_root_squash option.)
--------------------------------------------------------------------------------------------------------------
last -x reboot shows the VM start time and till reboot/shutdown time (simply total uptime of server)
last -x shutdown Shows the shutdown start time till start of the VM (simply total downtime of server)
----------------------------------------------------------------------------------------------------------------------
parted command with sector print
parted /dev/sda unit s print <= this shows sector wise information
fdisk -l /dev/sda <= this shows sector wise information
------------------------------------------------------------------------------------------------------------------------
11)check booting logs from journelctl from OS end
/usr/bin/journalctl --no-pager --boot 0 ==> Boot logs after VM up
12)OS logs Collect Examples
Command to collect sosreport( Redhat/CentOS/OracleLinux/Ubuntu)
sosreport --all-logs
Untar sosreport
tar -Jxvf sosreport-RHEL8-8888-2022-04-07.tar.xz
search with below keywork in sosreport
find . -type f -print0 | xargs -I {} -0 grep -i -H --color 'KEYWORD' "{}"
https://access.redhat.com/discussions/469323 - XSOS Good Tool but have not tried
Command to collect supportconfig( SUSE 12/15)
supportconfig -l (it collects rotated logs in addition to the current log file) - aLL logs
supportconfig ( collect witout rotated logs)
supportconfig -m ( collec minimal logs option)
untar supportconfig
tar -Jxvf scc_SUSE12.txz
tar.bz2 ==> tar -xvf file.tar.bz2
tar.gz ==> gunzip file.tar.gz && tar -xvf tar
Compressed Archive Folder (.xz)
file.xz
unxz file.xz
tar xvf file
mpio.txt ==> This file will be having fstab entries
12) rsync and multithread copy examples
rsync -anv --progress /pbsrestore/test.txt /pbsdata/test_data/
a=Archive;n= ;v=verbose;z=compress
rsync multithread copy advanced
cd source-dir;ls -1 | xargs -n1 -P4 -I% rsync -ar % destination-dir/
cd /test-rsync; ls -1 | xargs -n1 -P4 -I% rsync -ar % /data/rsync-data/ ===> works for local data copy
ps aux | grep rsync
pstree | grep rsync
top -c
For each file/directory its asking password
cd /test-rsync; ls -1 | xargs -n1 -P2 -I% rsync -ar % root@192.168.0.6:/data/rsync-data/
13) How to check current run level of RHEL7/8/SUSE12/15/Ubuntu 20/22/24
systemctl get-default ==> shows the current run level
- In systems using systemd (like RHEL 7 and later):
- Both
halt
andpoweroff
are linked tosystemctl
commands. halt
: Equivalent tosystemctl halt
(halts the system).poweroff
: Equivalent tosystemctl poweroff
(halts and powers off the system).
- Both
Command Comparison in systemctl
:
Command | Behavior |
---|---|
systemctl halt | Halts the system without cutting power. |
systemctl poweroff | Halts the system and powers it off. |
systemctl reboot | Restarts the system after halting all processes. |
Post a Comment