Geekblok

B10m, BOK, Joffie - old geeks on a blog

Entries Comments



Category: guides


rm -rf

18 June, 2008 (21:28) | guides, technical | By: Joffie

Every once in the several years I am a little too quick at the keyboard and manage to wipe a part of my home directory. I refuse to alias rm to rm -i because I always know what I am doing (Yeah right).
Yesterday it happened again. I managed to ctrl-c quickly, so I didn’t loose to many important files. It only got ~/bin/. Most of those files I already had on a backup machine.

I thought on what I could do to stop this from happening without converting to the alias rm=rm -i. The trick that I am now using is to make rm into a function, which I put into my ~/.bash_profile:

Read more »

Streaming your life with Yahoo! Pipes

13 June, 2008 (13:50) | guides, web2.0 | By: B10m

Yahoo! Pipes logoWith a plethora of social websites, it’s hard to keep track of everything. And like with all itches, people will try to make money out of it and come up with sites like FriendFeed, Lifestream, etc.

But what if you want to build something similar yourself? You’d have to download all your RSS feeds, combine them and most likely filter and sort them. Yahoo! Pipes comes in handy!

Read more »

shell tips and trick, part 2

19 January, 2008 (13:31) | guides, technical | By: Joffie

This trick is a bit bash specific instead of a real shell trick. On most unix systems you’ll find the commands dirname and basename. These are rather useless when you have got bash. First we’ll look at dirname.
The manual page of dirname states: dirname - strip non-directory suffix from file name. In bash this would be accomplished by parameter expansion:
$ I=/home/joffie/geekblok.txt; echo ${I%/*}
/home/joffie
The description from the man page of basename is: strip directory and suffix from filenames. So for example:
$ basename /home/joffie/geekblok.txt
geekblok.txt
The same can be accomplished with:
$ I=/home/joffie/geekblok.txt; echo ${I##*/}
geekblok.txt
The suffix part of the basename command can be done in two steps. What the command basename does is strip something from both sides of the string. So stripping suffix .txt from $I too:
$ I=/home/joffie/geekblok.txt; J=${I##*/}; echo ${J%.txt}
geekblok
Bash can also be used when searching and replacing. Take a look at:
$ I=/home/joffie/geekblok.txt; echo ${I/geek/cool}
coolblok.txt
More info can be found in the parameter expansion section of the man page of bash.

shell tips and trick, part 1

15 December, 2007 (16:21) | guides, technical | By: Joffie

Instead of another ssh guide, I thought it was about time for a first shell-scripting guide. In my daily job I often notice scripts that do work, but are not as efficient as could be. Say that I want the process id of the ssh daemon on my system. Loads of people will come up with something like:
ps -ef | grep sshd | grep -v grep | awk '{print $2}'

This does get the process id of sshd, but the above could also be written as:
ps -ef | awk '/sshd$/ {print $2}

And even this can still be written more efficient. Think about what you want to achieve. I asked for the process id of sshd. Basically the following would suffice:
cat /var/run/sshd.pid

Hey, I never really asked for a running sshd. But if I had asked for the process id of a running ssh daemon, the most simple solution would be:
ps -C sshd -o pid=

Or:
pgrep 'sshd'

Both just use one command instead of the four of the first example.

Hiding files in JPEGs

4 December, 2007 (12:19) | guides, images | By: B10m

You’ve probably heard about storing secret messages in JPEGs by means of steganography. But what if you have entire documents that you’d like to hide? As proof of concept, I showed this example to my coworkers.

We start out with a random JPEG, taken from my Flickr account:

fotobok.jpg

Now we create a simple zip file with a text document in it:

$ zip test.zip test.txt

And we cat the two files together:

$ cat fotobok.jpg test.zip > fotobok-test.jpg

File indeed recognizes this as an image:

$ file fotobok-test.jpg
fotobok-test.jpg: JPEG image data, JFIF standard 1.01

And you can see it here too:

fotobok-test.jpg

The only difference now is that we can unzip the file aswell:

$ unzip fotobok-test.jpg
Archive: fotobok-test.jpg

warning [fotobok-test.jpg]: 19881 extra bytes at beginning or within zipfile

(attempting to process anyway)

extracting: test.txt

Tada! Our highly secret test.txt is back!