AllTechWiki



A Place for All Technical Stuff Linux Cloud etc

LINUX BASIC COMMANDS

 1) Command to display only un commented lines of file


    gw-server:~ # cat /boot/grub/menu.lst | grep -v "^#"

2) Usage RAM on server Percentage wise

    gw-server:~ # free  | grep "buffers/cache" | awk '{print $3/($3+$4) * 100}'

    Free RAM availbe on server Percentage wise
    gw-server:~ # free  | grep "buffers/cache" | awk '{print $4/($3+$4) * 100}'

3)Check the files which is utilizing more space on particular FS

    Display File Size in KB in / of the server
    gw-server:~ #find / -xdev -type f -size +1M -exec du -sk {} ';' | sort -n

    Display File Size in MB in / of the serve
    gw-server:~ #find / -xdev -type f -size +1M -exec du -sh {} ';' | sort -n

     Display File Size in MB in current directory of the serve
     gw-server:~ #find . -xdev -type f -size +1M -exec du -sh {} ';' | sort -n

    [root@gw-server ~]#du -xh --max-depth 1 /var/opt/OV | sort -nr

4)Send mail to your email ID with below command from linux server

  gw-server:~ # echo "This is message body" | mail -s "This is Subject " pasemnaveen@gmail.com
  gw-server:~ # df -h | mail -s "gw-server df -h output" pasemnaveen@gmail.com

5)HOST Command : host command to find name to IP or IP to name in IPv4 or IPv6 and also query DNS records.

# host www.google.com
www.google.com has address 173.194.38.180
www.google.com has address 173.194.38.176
www.google.com has address 173.194.38.177
www.google.com has address 173.194.38.178
www.google.com has address 173.194.38.179
www.google.com has IPv6 address 2404:6800:4003:802::1014

Using -t option we can find out DNS Resource Records like CNAME, NS, MX, SOA etc.
# host -t CNAME www.redhat.com
www.redhat.com is an alias for wildcard.redhat.com.edgekey.net.

6)Ping with MTU Size 

 gw-server:~ #  ping -s 9000 SERVERNAME/IP

 gw-server:~ #  ping -s 9000 web-server
PING web-server.atg99.com (10.100.200.10) 9000(9028) bytes of data.
9008 bytes from web-server.atg99.com (10.100.200.10): icmp_seq=1 ttl=63 time=0.439 ms
9008 bytes from web-server.atg99.com (10.100.200.10): icmp_seq=2 ttl=63 time=0.483 ms
9008 bytes from web-server.atg99.com (10.100.200.10): icmp_seq=3 ttl=63 time=0.456 ms
^C
--- web-server.atg99.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.439/0.459/0.483/0.025 ms

MTU: The maximum transmission unit (MTU) of a network interface is the size of the largest block of data that can be transmitted as a single unit.
Anything larger than the MTU must be broken into smaller units prior to transmission.

Jumbo frames - High MTU Value 
Jumbo frames can reduce server overhead such as a big decrease in CPU usage when transferring larger file. Also you should see some increase in network throughput.

Ping with 1500 MTU and DO NOT Fragment and from Interface vlan1234

[root@gw-server ~]# ping -M do -s 1472 -I vlan1234 web-server
PING web-server (10.100.200.10) from 10.100.201.20 vlan1234: 1472(1500) bytes of data.

Options:
-M do : means do not fragment packate
-s    : size MTU
-I    : Ping from Interface

Here we are sending the packet(ping) from gw-server to web-server from particulate interface of    gw-server(vlan1234) with options

7)Shows the current mount status of file systems.

Some times FS went to readonly mode due to some reason ,if we want to know which FS went to readonly mode and which one is read/write

Below Command shows currently Read/Write FS on server
[root@gw-server ~]# cat /proc/mounts | grep rw,

Below Command shows currently Read only Mode FS on server
[root@gw-server ~]# cat /proc/mounts | grep ro,

8)Check Disks are local or storage
[root@gw-server ~]# cat /proc/scsi/scsi
[root@gw-server ~]# dmesg | grep -i "attached"

9)Top 10 memory process on server 
[root@gw-server ~]# ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -10
                                   
                                   ps -o pid,user,%mem,command ax | sort -b -k3 -r

9.1) check Process name
ls -l /proc/$PID/exe

top -H -p <pid>
ps -e -T | grep <application name or pid>
-e show's all processes
-T lists all threads

10)Find the Inode count in current directory
[root@gw-server ~]# find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn

11) Delete All files in current directory older than 5 days 
[root@gw-server ~]# find . -mtime +5 -delete;

12)Disk size with skipping the directories
[root@gw-server ~] # du -xsh *   ( -x   -> skip directories on different file systems)

du -sh exclude separate mounted FS 
1)df -sh | grep /opt -- Shows all mounts /opt
2)du -shc *
3)du -shc * --exclude=directory1 --exclude=directory=2 --exclude=directory3

13) How to check server is VM or Physical
dmidecode | egrep -i 'product'  OR dmidecode -t system  ===> shows the system info , like vendor , serial no & product name(hp/dell/cisco)
lshw -class system
dmesg | grep "Hypervisor detected"
hostnamectl status
systemd-detect-virt


14 ) Check Disks are local or storage
cat /proc/scsi/scsi
dmesg | grep -i "attached"

15) Monitor network traffic volume over interface
[root@gw-server ~] # watch ifconfig ens192
[root@gw-server ~] # iftop -i ens192

16) Check Reboot time
last -xF reboot runlevel


17) tcpdump

tcpdump -i any port 44304 -w /tmp/ssltrace.cap -- this will capture o/p in .cap file

tcpdump -e -v 'port 5443' -- this will give o/p in terminal only

tcpdump -vvv -ni eth0 port 6556 -w /tmp/AZR-EUSL1109.pcap

tcpdump -vvv -ni eth0.100 port 6556 -w /tmp/azr-eusl1015.pcap

18) yum whatprovides showmount --- > shows the package name which needs to be installed 


19) network interface card status check
ip link show 
for i in $( ls /sys/class/net ); do echo -n $i: ; cat /sys/class/net/$i/carrier; done
for i in $( ls /sys/class/net ); do echo -n $i: ; cat /sys/class/net/$i/operstate; done


20) For Loop Example
for i in `cat backupserver.txt` ; do ping -c1 $i 2>&1 | tee  >> backupup-pings-outout.txt; done
for i in `cat backupserver.txt`; do echo $i; dzdo -i ssh $i ' /usr/bin/simpana restart '; echo "========"; echo; echo; done status.txt

21)/usr/bin/find: Argument list too long error
When /usr/bin/find: Argument list too long error
USE THIS:
find /u01/app/oracle/diag/rdbms/TEST/TEST/trace/ -name '*.trm'  -mtime +30 -exec /bin/rm {} \;

INSTEAD OF THIS!!!
find /u01/app/oracle/diag/rdbms/TEST/TEST/trace/*.trc +30 -exec /bin/rm -rf {} \;

22) kill all process 

kill -9 $(ps -ef |grep dsmc |grep -v pts/4 |awk '{print $2}')

Post a Comment

Previous Post Next Post

Basic Useful Links