Variables · Functions · Interpolation · Brace expansions · Loops · Conditional execution · Command substitution · One-page guide to Bash scripting
Source: Bash scripting cheatsheet
Variables · Functions · Interpolation · Brace expansions · Loops · Conditional execution · Command substitution · One-page guide to Bash scripting
Source: Bash scripting cheatsheet
The other day I had enough calculating the time so I just wrote this script:
cat > ~/bin/timediff
#!/bin/sh
if [ -z $2 ]; then
echo "usage: $0
echo
echo "ex. $0 11:49 12:51"
exit 1
fi
end=`date +%s -d"$2"`
start=`date +%s -d"$1"`
diff=$(($end-$start))
diff=$(($diff/60))
hours=$(($diff/60))
min=$(($diff%60))
# Prepend a 0 if minute <10
if [ ${#min} -eq 1 ]; then
min=0$min
fi
echo "$hours:$min"
Of course, it works in some cases only. This one is fine:
$ sh ~/bin/timediff 11:49 12:51
1:02
Whereas this one will not work:
$ sh ~/bin/timediff 11:49 1:51
-9:-58
But the output is quite obvious.
In order to rescan your SCSI bus on a Linux server, simply run the following command:
echo '- - -' > /sys/class/scsi_host/host0/scan
NOTE: Your scsi target could be different than host0.
Running ‘dmesg‘ should show you a SCSI rescan as the last output.
UK-based Raspberry Pi Foundation is working on a credit card size, $25 PC which will redefine computing. The tiny computer runs on Linux. It supports Debian, Fedora and Arch Linux. Initially Ubuntu, as its based on Debian, was supported but it doesn’t at the moment. Read more here
It took me a while to find this, so I’m just blogging it so other people
will be able to find it.
I wanted to send a desktop
notification using
pynotify, but using a GTK+ stock
icons.
With the following snippet, I managed to do it.
import pynotify pynotify.init("myapp") import gtk n = pynotify.Notification(summary="Summary", message="Message!") n.set_icon_from_pixbuf(gtk.Label().render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_LARGE_TOOLBAR)) n.show()
Note that the use of a Label is just to have a widget instanciated to use
the render_icon() method. It could be any widget type as far as I
understand.
During the OpenRheinRuhr I noticed that a friend of mine didn’t know
about zgrep
and friends. So I told him what other grep
variations I know and he told me about some grep variations I didn’t
know about.
So here’s our collection of grep wrappers, derivatives and variations.
First I’ll list programs which search for text in different file
formats:
grep through what | Fixed Strings | Wildcards / Basic RegExps | Extended RegExps | Debian package |
---|---|---|---|---|
uncompressed text files | fgrep | grep | egrep | grep |
gzip-compressed text files | zfgrep | zgrep | zegrep | zutils, gzip |
bzip2-compressed text files | bzfgrep | bzgrep | bzegrep | bzip2 |
xz-compressed text files | xzfgrep | xzgrep | xzegrep | xz-utils |
uncompressed text files in installed Debian packages | dfgrep | dgrep | degrep | debian-goodies |
gzip-compressed text files in installed Debian packages | – | dzgrep | – | debian-goodies |
PDF documents | – | – | pdfgrep | pdfgrep |
POD texts | podgrep | – | – | pmtools |
E-Mail folder (mbox, MH, Maildir) | – | mboxgrep -G | mboxgrep -E | mboxgrep |
Patches | – | grepdiff | grepdiff -E | patchutils |
Process list | – | – | pgrep | procps |
Gnumeric spreadsheets | ssgrep -F | ssgrep | ? | gnumeric |
Files in ZIP archives | – | – | zipgrep | unzip |
ID3 tags in MP3s | – | – | taggrepper | taggrepper |
Network packets | – | – | ngrep | ngrep |
Tar archives | – | – | targrep / ptargrep | perl (Experimental only for now) |
And then there are also greps for special patterns on more or less
normal files:
grep for what | uncompressed files | compressed files | Debian package |
---|---|---|---|
PCRE (Perl Compatible Regular Expression) | pcregrep (see also the grep -P option) |
zpcregrep | pcregrep |
IP Address in a given CIDR range | grepcidr | – | grepcidr |
XPath expression | xml_grep | – | xml-twig-tools |
One question is though still unanswered for us: Is there some kind of
meta-grep which chooses per file the right grep from above by looking
at the MIME type of the according files, similar to xdg-open.
Other tools which have grep in their name, but are too special to
properly fit into the above lists:
visgrep
Includes contributions by Frank Hofmann and Faidon Liambotis.