User Tools

Site Tools


wiki:bash_commands

Differences

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

Link to this comparison view

Next revision
Previous revision
wiki:bash_commands [2022/09/19 23:53] – created antisawiki:bash_commands [2023/08/07 10:30] (current) – add Remove old unused kernels antisa
Line 2: Line 2:
  
 ====== Bash commands ====== ====== Bash commands ======
-Remove first character:+===== Remove first character: ===== 
  
   for f in *; do mv "$f" "${f:1}"; done   for f in *; do mv "$f" "${f:1}"; done
  
-Add 8 to filename:+==== Add 8 to filename: ==== 
  
   for f in *; do mv "$f" "8$f"; done   for f in *; do mv "$f" "8$f"; done
  
 +==== Sort folders by disk usage, larger first: ====
 +  du -sh /* | sort -hr
 +
 +==== Checksum directory recursively ====
 +
 +  find /var/lib/mysql -type f -print0 | xargs -0 sha256sum > mysql.sha256sum
 +
 +==== Comment and uncomment lines containing specific strings ====
 +  sed -e '/multiverse/s/^/#/' -i /etc/apt/sources.list
 +  sed -e '/multiverse/s/^#//' -i /etc/apt/sources.list
 +
 +==== Search and replace strings in multiple html files: ====
 +  for file in $(grep -cr --include "*.html" "somestring" . | awk -F ":" '{print $1}');do sed -i 's/\bsomestring\b/newstring/g' $file;done
 +
 +\b is word boundary, meaning it won't select strings like string_somestring_smth_smth Put sed -n... and ..newstring/gp' to just see the changes without actually making them.
 +
 +==== Print from certain line to certain line: ====
 +
 +  zcat server_20170726-060002.log.gz | awk '/2017-07-25\ 20:54:59.381/,/2017-07-25\ 21:16:00.948/' - > incident.txt
 +
 +==== Sed add word/string after specific string on same line i.e. add "blablah" after " localhost ": ====
 +  sed 's/\blocalhost\b/& blablah/' file
 +
 +
 +==== Print disk usage, summarize in GB ====
 +   du -s /var/lib/mysql/mydb/{table1,table2,table3}.* | awk '{ sum+=$1} END {printf sum/1024^2; print " GB"}'
 +
 +==== Remove old unused kernels ====
 +
 +  sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'|grep -E "(image|headers|modules)" | grep -v hwe | xargs sudo apt-get -y purge
 +  
 ====== Tested on ====== ====== Tested on ======
   *    * 
wiki/bash_commands.1663624422.txt.gz · Last modified: 2022/09/19 23:53 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki