Skip to main content

Posts

Days Between

A little script to tell you the days between two YYYYMMDD dates: #!/bin/bash function usage { echo "date {date} {date}, where date is in the format YYYYMMDD" } function absolute_value { echo $1 | sed s/-// } # Print help, if number of args wrong if [ -z $2 ] then usage 1>&2 exit 1 fi if [ $3 ] then usage 1>&2 exit 1 fi # The dates we want to days between DATE_ONE="$1" DATE_TWO="$2" # provide the original date instead of "now" and ask for "seconds since epoch" DATE_ONE_EPOCH=$(date -d "${DATE_ONE}" "+%s") DATE_TWO_EPOCH=$(date -d "${DATE_TWO}" "+%s") #Math DAYS=$(($((${DATE_ONE_EPOCH} - ${DATE_TWO_EPOCH}))/$((60*60*24)))) absolute_value $DAYS ------ Note the unmath in "absolute_value" ;-)

Linux Live Search...

So... The other day I decided to set up 'locate' to find files in my home network shares, /home/ghostis and /sandbox/ghostis. To do so, I did the following: % mkdir /home/ghostis/Documents/locate Added the an updatedb job to my crontab on my laptop: 15,30 * * * * updatedb --netpaths='/home/ghostis /sandbox/ghostis' --output=/home/ghostis/Documents/locate/locatedb --localpaths=' ' Now I can do faster searches of filenames via: locate -d ~/Documents/locate/locatedb sometextinfilename But, then I thought, "What's the absurd extreme?" Linux Live Search! So I baked a quick bash script: % cat linux_live_search.sh #!/bin/bash clear echo "Please type something. (Escape spaces. Ctrl-C to quit)" echo "------------------------------------------" echo "Query: $WORD" echo "------------------------------------------" while read -s -n1 KEY do clear if [ "$KEY" = "" ] then WORD=`echo "$WOR...