Bash convert seconds to human readable
function displaytime { local T=$1 local D=$((T/60/60/24)) local H=$((T/60/60%24)) local M=$((T/60%60)) local S=$((T%60)) (( $D > 0 )) && printf ‘%d days ‘ $D (( $H > 0 )) && printf ‘%dRead More…
function displaytime { local T=$1 local D=$((T/60/60/24)) local H=$((T/60/60%24)) local M=$((T/60%60)) local S=$((T%60)) (( $D > 0 )) && printf ‘%d days ‘ $D (( $H > 0 )) && printf ‘%dRead More…
We need to run ifconfig and look for the status line. Remember this about ifconfig output: * if “status: active“, the port is linked up and sending traffic (now you just needRead More…
If your system gzips and rotates your logs. You can use this trick to search thru all of them. # zgrep -i — “SEARCHTERM” $(ls -1Str /var/log/messages*) Another way # zgrep -iRead More…
Imagine a file list, list.txt, like this one image1.jpg image2.jpg image3.jpg Naturally you could deal with it like so cat list.txt | while read i; do FILE="$i" dosomething "$FILE" done Or justRead More…
Here I show you how to repeat a command until it finishes successfully. This should only be done with programs that support resume and also have legit exit codes (or else theyRead More…
When you are running a command hit Control-T anytime, its very useful when a command looks stuck. It causes the kernel to spit out a line similar to the following: load: 0.69Read More…
Screen the app that can split screens like so, is not too intuitive when it comes to scrolling thru your bash shell. Notice where the cursor is in the diagram below, itsRead More…
To print tab characters (and other control characters) you cant just press Tab because tab is a special auto complete char in bash. Control-V then Tab or Control-V then Control-I (also knownRead More…
The version of FreeBSD 8.0 that I am using is missing tee & tee -a (tee append) You know tee as in write on screen & file: date | tee thedate.txt Which will runRead More…
Source: http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed Replace with space: Use this solution with GNU sed: someoutput | sed ':a;N;$!ba;s/\n/ /g' Here is cross-platform compatible syntax which works with BSD sed (FreeBSD 8 confirmed): someoutput | sed -eRead More…