Easy accurate timestamps and a few other scripts

dtx0

New member
Since I recommended this section being created, I figured I'd give out a few tiny snippet gems I use all the time.

Note that these functions/aliases are for Bash; thus, they may need to be altered to meet your needs. The reason why I didn't include guards (e.g., OS/env checks) was because adding them to these scripts will only confuse people who don't know how to program. If, however, someone asks (a) how to implement these checks and incorporate them into some script; and/or (b) how to port a Bash script to, say, Zsh; and/or, (c) how to convert an inline Perl script to, say, Python, then, I'll be happy to guide them in the right direction. (N.B., Homework questions DO NOT count. Do not ask me how to fix your assignment, as I will report you to the moderators.)


This function will accept a valid IPV4 address (i.e., numbers, do not confuse with domain name) and query ipinfo.io to see where the IP address is located.
Code:
geoip_location() {
? ? # EXAMPLE: << curl ipinfo.io/23.66.166.151 >>
? ? echo "";
? ? echo "Acquiring location of $1 ..."
? ? echo "";
? ? echo "[------------------------------------------------------------------------------]";
? ? echo "[------------------------------------------------------------------------------]";
? ? curl ipinfo.io/$1
? ? echo "";
? ? echo "[------------------------------------------------------------------------------]";
? ? echo "[------------------------------------------------------------------------------]";
? ? echo "";
}



Code:
now() {
? ? perl -e 'use Time::HiRes qw(time); print time';
}



Code:
alias unixtime='python -c "from time import time as time; print(time())"'





This script will recursively search directories and list unique file types (and/or directories) found
Code:
# recursive search and listing of unique file types in a directory
lsuf() {
?? ?if [ -z $1 ]; then
?? ??? ?printf "\nIncorrect use.\n> $0 <PATH>\n";
?? ?else
?? ??? ?find $1 -type f | sed 's/.*\.//' | sort | uniq -c;
?? ?fi
}