Difference between revisions of "Useful Linux Commands"

From DFWLPiki
Jump to: navigation, search
(Created page with "Category:Linux ==Useful Random Bash Command Line Usages== To find all matching files names in a directory hierarchy find /path/to/dir -type f | rev | sort | sed -nr ':a...")
 
(Useful ways to use Sed in Linux)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Linux]]
 
[[Category:Linux]]
 +
 +
==Measure disk i/o performance==
 +
dd if=/dev/zero of=outfile bs=1M count=1024 conv=fdatasync; rm -rf outfile
 +
dd if=/dev/zero of=outfile bs=1M count=2048 conv=fdatasync; rm -rf outfile
 +
dd if=/dev/zero of=outfile bs=1M count=4096 conv=fdatasync; rm -rf outfile
 +
 +
==Refresh disk storage system after adding new disks==
 +
for i in `ls /sys/class/scsi_host`; do echo "- - -" > /sys/class/scsi_host/${i}/scan; done
  
 
==Useful Random Bash Command Line Usages==
 
==Useful Random Bash Command Line Usages==
Line 10: Line 18:
 
To uncomment something in a config file:
 
To uncomment something in a config file:
 
  sed -i 's/^#compress/compress/' /etc/logrotate.conf
 
  sed -i 's/^#compress/compress/' /etc/logrotate.conf
 +
sed -i 's/^#UseDNS no/UseDNS no/' /etc/ssh/sshd_config
 
To remove "rhgb quiet" from grub.conf:
 
To remove "rhgb quiet" from grub.conf:
 
  sed -i 's/rhgb quiet//g' /boot/grub/grub.conf
 
  sed -i 's/rhgb quiet//g' /boot/grub/grub.conf

Latest revision as of 19:34, 6 May 2022


Measure disk i/o performance

dd if=/dev/zero of=outfile bs=1M count=1024 conv=fdatasync; rm -rf outfile
dd if=/dev/zero of=outfile bs=1M count=2048 conv=fdatasync; rm -rf outfile
dd if=/dev/zero of=outfile bs=1M count=4096 conv=fdatasync; rm -rf outfile

Refresh disk storage system after adding new disks

for i in `ls /sys/class/scsi_host`; do echo "- - -" > /sys/class/scsi_host/${i}/scan; done

Useful Random Bash Command Line Usages

To find all matching files names in a directory hierarchy

find /path/to/dir -type f | rev | sort | sed -nr ':a N;/^([^/]*\/).*\n\1/p;D;ba' | uniq | rev

Useful ways to use Sed in Linux

These first two examples are used in linux installation scripts as %post activities.

To uncomment something in a config file:

sed -i 's/^#compress/compress/' /etc/logrotate.conf
sed -i 's/^#UseDNS no/UseDNS no/' /etc/ssh/sshd_config

To remove "rhgb quiet" from grub.conf:

sed -i 's/rhgb quiet//g' /boot/grub/grub.conf

Examples from various task scripts which i will categeorize and label later: (some will be repeats)

[root@d0lppb021 syssupport]# grep sed *.sh
addjhorne.sh:sed -i '/^jhorne/ c\jhorne:yaaaaaaaaaaaaaaaaaaaaaaaaaaaayyyyyyyyyyyyyyyyyyyyyy:0:99999:7:::' /etc/shadow
filesystem_lv_mysql-vg01-500G-sda.sh:sed -i '/lv_mysql/d' /etc/fstab
filesystem_lv_postgres-vg01-500G-sda.sh:sed -i '/lv_postgres/d' /etc/fstab
fixbacula.sh:sed -i "s/set-hostname/$HOSTNAME/g" /etc/bacula/bacula-fd.conf
fixpostfix.sh:sed -i "s/^#myhostname = virtual.domain.tld/myhostname = $HOSTNAME.skopos.me/g" /etc/postfix/main.cf
fixpostfix.sh:sed -i 's/^#mydomain = domain.tld/mydomain = skopos.us/' /etc/postfix/main.cf
fixpostfix.sh:sed -i 's/^#myorigin = $mydomain/myorigin = $mydomain/' /etc/postfix/main.cf
initialovirt.sh:sed -i 's/Santiago//g' /etc/redhat-release
initialovirt.sh:sed -i "s/set-hostname/$HOSTNAME/g" /etc/bacula/bacula-fd.conf
initialphysical.sh:sed -i 's/Santiago//g' /etc/redhat-release
initialphysical.sh:sed -i "s/set-hostname/$HOSTNAME/g" /etc/bacula/bacula-fd.conf
initialpxe.sh:sed -i "s/set-hostname/$HOSTNAME/g" /etc/bacula/bacula-fd.conf
initialvirtual.sh:sed -i "s/set-hostname/$HOSTNAME/g" /etc/bacula/bacula-fd.conf
readyesno.sh:        [Yy]* ) umount /opt/mysql; pvcreate /dev/sda1; vgcreate vg01 /dev/sda1; lvcreate -L 500G -n lv_mysql vg01; mkfs.ext4 /dev/vg01/lv_mysql; sed -i '/lv_mysql/d' /etc/fstab; echo "/dev/mapper/vg01-lv_mysql /opt/mysql              ext4    defaults,_netdev 0 0" >> /etc/fstab; cat /etc/fstab; mount -a; df -h; break;;
setupssl.sh:sed -i "s/localhost.crt/skopos.me.crt/g" /etc/httpd/conf.d/ssl.conf
setupssl.sh:sed -i "s/localhost.key/skopos.me.key/g" /etc/httpd/conf.d/ssl.conf

This example is from to change a PXE profile file, to add ksdevice parameter:

sed -i 's/^    append initrd/    append ksdevice=em1 nicdelay=50 linksleep=50 initrd/' /tftpboot/linux-install/pxelinux.cfg/0*

Yum Configuration to Skip a Package

I have had a problem with Fedora overwriting the respository version of Cacti with the source version that I had previously installed. To prevent yum from updating a specific package, I have found this switch:

yum -y update --exclude=cacti

There is also a facility to handle this directly, from within /etc/yum/yum.conf.