Some Useful Linux Commands
Linux Sed command to change values inside file
# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
-
PERL script to check Linux machine type
# perl -MConfig -e ‘print “$Config{myarchname}\n”;’
-
To check Fibre cable status – Simple script
checkfiber.sh
#!/bin/sh
ls /sys/class/fc_host | while read i; do
echo $i
cat /sys/class/fc_host/$i/port_state
done
-
Copy files by giving list as text file
# xargs cp -t /home/example/pictures/jpegdir < filelist.txt
-
To disable gfs hang lockout messages on /var/log/messages
# echo 0 > /proc/sys/kernel/hung_task_timeout_secs
To disable IPv6 add following lines in /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
And reboot the system.
If you want to disable IPv6 without rebooting your system, then you have to run following commands:
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6
OR
sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1
-
To kill specific login section
# w
root pts/0 :0.0 10Jan13 38days 0.03s 0.03s bash
root pts/1 ws-zhaider.c 02:13 59.00s 7.64s 7.62s /bin/sh
root pts/2 fedora16.benvin. 08:33 0.00s 0.04s 0.01s w
# skill -KILL -v pts/1
-
SSH Debugging – To check where the connection is dropping
# ssh -vvv -i$privatekey -oBatchMode=yes user@host
-
SCSI rescan on RHEL4
# echo “- – -” > /sys/class/scsi_host/host0/scan
(host0 is just an example.)
10. To Clear Swap memory on RHEL
/sbin/sysctl vm.drop_caches=3
#sync; echo 3 > /proc/sys/vm/drop_caches
11. Find Larget File in Linux
# du -k | sort -n | perl -ne ‘if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf (“%6.1f\t%s\t%25s %s\n”,($1/(2**(10*$m))),((“K”,”M”,”G”,”T”,”P”)[$m]),”*”x (1.5*$l),$2);}’
the output is like below:
12. Find FC ID WWNN of a disk/LUN
# systool -c fc_host –v
# systool -c fc_transport -v
2.4.x Kernels
> cat /proc/scsi/[hba_type]/(n)
where hba_type is the driver (e.g. lpfc for Emulex) and (n) is the HBA number.
2.6.x Kernels:
> cat /sys/class/scsi_host/host(n)/[port_name|node_name]