User Tools

Site Tools


bash_oneliners

BASH oneliners

  • Whats my WAN IP?
dig +short myip.opendns.com @resolver1.opendns.com
  • Find large files, print 10 largest files in dir
find . -printf '%s %p\n'|sort -nr|head
  • size of all files older than mtime
find . -mtime +7 -print0 | du -hc --files0-from - | tail -n 1
  • To find the largest file in all sub-directories:
find . -type f -exec ls -s {} \; | sort -nr | awk 'NR==1 { $1=""; sub(/^ /, ""); print }'
  • grep for valid IP Addresses.
grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" file.txt
  • show used inode count for subdirectories.
find */ | sed 's!/.*!!' | uniq -c
  • free all caches
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
  • rescan all SCSI buses
for i in /sys/class/scsi_host/host{0..32}/scan; do echo "- - -" > $i; done
  • enlarge LVM
fdisk /dev/sdk
#set partition type to Linux LVM (type 8e)
pvcreate /dev/sdk1
vgextend VolGroupDB /dev/sdk1
lvextend -l +100%FREE /dev/mapper/VolGroupDB-data
resize2fs -p /dev/mapper/VolGroupDB-data
#for xfs use xfs_growfs /dev/mapper/VolGroupDB-data
parted -a optimal /dev/sdc mklabel gpt
parted -a optimal /dev/sdc mkpart p 0% 100%
parted -a optimal /dev/sdc set 1 lvm on
vgextend VGEXL /dev/sdf1
lvresize -l +100%free /dev/mapper/VGEXL-exllv
  • Enlarge LVM 2
echo '1' > /sys/class/scsi_disk/0\:0\:3\:0/device/rescan
yum install cloud-utils-growpart
growpart  /dev/sdd 1
pvresize /dev/sdd1
lvextend -l +100%FREE /dev/mapper/VGKUB-lv_kub
xfs_growfs /dev/mapper/VGKUB-lv_kub
bash_oneliners.txt · Last modified: 2023/07/27 13:28 by admin