Posts Tagged ‘Tips’

locate your files!

Tuesday, April 24th, 2007

This is just a quick set of tips about the super-duper-handy locate command at, well, the command line.

First off, it’s called locate. If you don’t have it installed, it may be contained in a package called findutils-locate (a “shout-out” to all my fellow SUSE distro users)

Secondly, to manually update the locate command’s database (it automatically runs each night), you type (as root): updatedb …and wait for a while.

Thirdly, in your shell of choice, alias locate='locate -i' …and you’ll get case-insensitive locate! Combined with grep (especially grep -i; i also happens to be its case-insensitive flag too), you’ll be finding files in your hard drive quite easy from now on…

I use locate all the time, especially whenever I’m looking for a quick path to find a graphic I of which know the filename (or part of a filename). For example:

locate information | grep png | grep 48

Will return something like (depending on your distribution):


Search history in bash

Thursday, October 13th, 2005

This is another quick tip: to search typed history at a bash prompt, hit control-r and start typing a command you used previously. It doesn’t have to start with what is typed, as it returns matches which contain the searched text.

Hit control-r again (while searching), and it will jump back further in history and search with the same text.

Hitting enter when bash finds something will run the command while hitting the arrow keys will allow you to move around and edit the command. The escape key will also exit the search and place the historical command on your command line. To cancel the search entirely, use control-c and you’ll be returned to a clean prompt (although the matching string will be presented above where you’re typing).

Super-useful inputrc

Thursday, October 13th, 2005

You either want to place the following in ~/.inputrc or /etc/inputrc… I’ve found that while ~/.inputrc works sometimes, it doesn’t on all systems.

"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case On

All lines except the last enable nice readline & bash cursor movement (control + arrow keys and what not) while the last line turns on case insensitivity for tab-completion, enabling you to have folders and files of mixed case characters while not having to type the capital letters. (You can have a directory called “Documents” and tab-complete by tying “doc<tab>

I’ve been enjoying the above for a while now, and I think it really should be the default settings for distributions.

Note: This works for Linux, Mac OS X, and *BSD. It might work for people using Bash on Windows, but you’re on your own there. (: