Linux: Find text in a large number of files

If you need to find a string in a file, you would typically use:
grep -H "string to find" filename.ext
However, grep doesn’t handle a large number of files well. If you specify grep "string" * or even grep "string" `find ./`you may find yourself facing this error:
bash: /bin/grep: Argument list too long
If you need to search for a string in a lot of files then you can use a simple bash script to do the searching for you.

In this sample, I am looking for a string “sample string” in a directory named “./sample/”:
for i in `find ./sample/`; do grep -H "sample string" $i; done
This uses the find command to do the searching. It actually returns a list of filenames, which we can then grep one-by-one. The -H option tells grep to let us know the filename it found the string in so we can go right into that file to find the location of it.

Linux: Mount ISO Image as directory

Here is a handy little shortcut I recently figured out (it took me long enough, didn’t it!).

You can mount an ISO image as a directory in linux. Very nice for when you are remote and want to have a CD on that system.

mount -t iso9660 -o loop imagename.iso /mnt/isoimage

Foxit PDF Reader 2.0

Don’t you hate it when your browser locks up because you unknowlingly clicked on a PDF File? Let’s face it – Adobe’s PDF Format rocks but the reader takes way to long to load and also locks your PC up.

Foxit Software just released Foxit PDF Reader 2.0. If you haven’t tried it already, you need to get this software (Windows Only). Trust me, you won’t be dissapointed.

Download Foxit PDF Reader 2.0

Closing a Firefox Window with Javascript

I recently had a problem where I was opening a browser window from an e-mail client. After taking a survey, I wanted a button to close this same window. In IE, it was fine to simply use window.close(); to close the window. However, Firefox, the evil genius that it is, will not let you do that because it believes you did not click to open this window in the first place. In order to trick it, you quick load a blank page then close it. The code:

Close this window

So now, when you click the link, it closes the browser window. It works in both IE and Firefox 1.5 (and I believe others as well, but not personally tested). Finding that snippet of code saved me a lot of time! So I hope someone else finds it useful.

Update, May 1 2008:

This code only works on Firefox 1.5 and IE. In Firefox 2.0, Unless a website opened up a window – it can not close it. So, in my case I want to close the window after a user takes a survey, opened from an email window. Firefox 2.0 gives this error: Scripts may not close windows that were not opened by the script. I’m not sure what the right answer is here. They are doing it to prevent malicious scripts from closing windows. But even if they added an option to change that, most users wouldnt have it enabled by default.

So… where does that leave us? Please let me know if anyone knows of code that can close a window with Javascript in Firefox 2.x or 3.x.

Greasemonkey + Duggmirror Script = Awesome

Greasmoney + Duggmirror

Don’t you hate it when you try to visit a digg story and the site has been dugg? Use the greasemonkey firefox plugin and this duggmirror greasemoney script to add three links to each digg entry – the duggmirror archive, Coral NYU Mirror, and the Google Cache of the page, all with a nice graphical interface. It’s easy too:

  1. Install Firefox (you mean you haven’t already?)
  2. Install Greasemonkey plugin
  3. Restart Firefox
  4. Visit the duggmirror script‘s page and click “install this script”. A little box will pop up at the top of the browser screen, asking you for permission to install it.

That’s it! When you visit digg – you will see the extra links next to the post title. It works in any OS that firefox support (I’ve personally tested on Windows XP, Vista, and Ubuntu).

Visual.Syntax is my choice for code highlighting

I am using the Visual.Syntax code highlighting plugin by Matthew Delmarter. There were some code highlighter plugins out there, but they were all pretty complicated and the output was fancier – a little too fancy. I wanted something simple to copy/paste from and Visual.Syntax won the day for me. iG:Syntax Hiliter is a close second and I may still use it some day. It does neat things like line numbering and highlighting for a large amount of languages; but I did not find it as simple to use as Visual.Syntax. In case you were wondering, both of them work with WordPress 2.x.

A note on fonts…

Considering that I plan on using a lot code on this site, I put a lot of thought into the best fonts to use for readability. I ended up going by a programmers font guide from Mr. Lowing. The code highlights on these pages use the following fonts (in order of preference/availability): Bitstream Vera Sans Mono, Lucida Console, Consolas, Courier, monospace.

The result is below:

If everything went right, it should look like one of the following:


If you do not have one of those fonts, you should still see a monospaced font.