User Tools

Site Tools


bash_oneliners

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
bash_oneliners [2015/12/07 10:42] adminbash_oneliners [2025/08/06 12:07] (current) admin
Line 2: Line 2:
  
  
-  * Remove offending key from known_hosts file with one command 
-<code> 
-$ sed -i 18d .ssh/known_hosts 
-</code> 
   * Whats my WAN IP?   * Whats my WAN IP?
 <code> <code>
-dig +short myip.opendns.com @resolver1.opendns.com+dig +short myip.opendns.com @resolver1.opendns.com
 </code> </code>
   * Find large files, print 10 largest files in dir   * Find large files, print 10 largest files in dir
 <code> <code>
-find . -printf '%s %p\n'|sort -nr|head+find . -printf '%s %p\n'|sort -nr|head 
 +</code> 
 +  * size of all files older than mtime 
 +<code> 
 +find . -mtime +7 -print0 | du -hc --files0-from - | tail -n 1
 </code> </code>
   * To find the largest file in all sub-directories:   * To find the largest file in all sub-directories:
 <code> <code>
-find /path/to/folder -type f -exec ls -s {} \; | sort -nr | awk 'NR==1 { $1=""; sub(/^ /, ""); print }'+find -type f -exec ls -s {} \; | sort -nr | awk 'NR==1 { $1=""; sub(/^ /, ""); print }' 
 +</code> 
 +  * grep for valid IP Addresses. 
 +<code> 
 +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 
 +</code> 
 +  * show used inode count for subdirectories. 
 +<code> 
 +find */ | sed 's!/.*!!' | uniq -c 
 +</code> 
 +  * free all caches 
 +<code> 
 +free && sync && echo 3 > /proc/sys/vm/drop_caches && free 
 +</code> 
 +  * rescan all SCSI buses 
 +<code> 
 +for i in /sys/class/scsi_host/host{0..32}/scan; do echo "- - -" > $i; done 
 +</code> 
 +  * enlarge LVM 
 +<code> 
 +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 
 +</code> 
 +  * Enlarge LVM 2 
 +<code> 
 +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 
 +</code> 
 + 
 +  * polkit logging for debugging  
 +<code> 
 + 
 +cat /etc/polkit-1/rules.d/50-apt.rules 
 + 
 +polkit.addRule(function(action, subject) { 
 +    polkit.log("Evaluating action: " + action.id); 
 +    polkit.log("User: " + subject.user + ", Groups: " + subject.getGroups()); 
 + 
 +    if (action.id.startsWith("org.freedesktop.packagekit.") || 
 +        action.id == "org.debian.apt.update-cache" || 
 +        action.id == "org.debian.apt.upgrade" || 
 +        action.id == "org.debian.apt.remove" || 
 +        action.id == "org.debian.apt.upgrade-packages" || 
 +        action.id == "org.debian.apt.install") { 
 +        polkit.log("Authorization granted for action: " + action.id); 
 +        return polkit.Result.YES; 
 +    } 
 + 
 +    polkit.log("Authorization denied for action: " + action.id); 
 +});
 </code> </code>
bash_oneliners.1449484930.txt.gz · Last modified: (external edit)