Category: Scripting
‘tail -f’ with highlight
This is an example of how you can use tail with colors. # tail -f /var/log/maillog | perl -pe ‘s/colorthisword/\e[1;32;40m$&\e[0m/g’ The ;;; values explained 0 all attributes off 1 bold 32 foreground green 40 background black “colorthisword” can be any perl regular expression: (foo|bar) highlight the strings foo and bar \b((foo|bar)\b highlight the words foo […]
Rename files by wildcard pattern and correct the EXIF timestamp metadata
This is a little script I’ve written to correct all my image files since the EXIF timestamp information is one hour out of sync. The filenames have been renamed to comply to the EXIF information and has to be renamed again because of the one hour scew. The filename can look something like this 20080102-1201_DSC_0910.JPG […]
Oneliner to determine directory size
This is a simple oneliner to determine which user has used most diskspace in their /home directory du -sm $(find /home -type d -maxdepth 1 -xdev) | sort -g The result could look something like this … 215 /home/userT 1367 /home/userB 10865 /home/userL 25326 /home/userY 116328 /home/userH 154426 /home/ The numbers to the left is […]
Generate a /etc/hosts file from the command line
This is a simple example of how you can populate a /etc/hosts file with 100 IPs and hosts from the command line # N=1; for i in $(seq -w 100); do echo “192.168.99.$N host$i”; P=$(expr $P + 1); done >> /etc/hosts The result file /etc/hosts 192.168.99.201 host001 192.168.99.201 host002 192.168.99.201 host003 192.168.99.201 host004 192.168.99.201 host005 […]