When Spotlight gets corrupted you can use the mdutil tool to clea up or reset the metadata stores as follows. Keep in mind that you have to execute it as an admin user if you want to reset the entire disk.
To erase all the local stores
To set the indexing status ON
Other useful parameters
-p Spotlight caches indexes of some network devices locally. This option requests that a local caches be flushed to the appropriate network device.
-E This flag will cause each local store for the volumes indicated to be erased. The stores will be rebuilt if appropriate.
-i on | off
Sets the indexing status for the provided volumes to on or off. Note that indexing may be delayed due to low disk space or other conditions.
-s Display the indexing status of the listed volumes.
-a Apply command to all volumes.
-v Print verbose information when available.
Open the Terminal.app, copy and paste the following command and hit Return.
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user
After upgrading to Lion you may not see the ~/Library folder. If you want to unhide it, try the following command on the Terminal.app
chflags nohidden ~/Library
The changes to take effect the Finder should be restarted
To hide the ~/Library folder
When you want to access a remote terminal using ssh, general procedure is to run something similar to,
and then enter the password. However if you have to do it regularly, entering the ssh command and the password can become annoying. The following guide will give you some tips to easily manage the above process without all the hassle.
SSH to a remote host from a local machine without entering the password.
- Open the Terminal.app (/Applications/Utilities/Terminal.app).
- Navigate to the .ssh folder.
If the .ssh directory doesn’t exist you can create it using,
- Create security key pairs if they don’t exist.
- Copy the generated public key to the remote host.
scp id_rsa.pub username@server:~/.ssh/
- SSH into the remote host in a regular fashion for the one last time.
Copy the id_rsa.pub key to the authorized_keys list.
cat id_rsa.pub >> .ssh/authorized_keys
- Remove the id_rsa.pub file.
- Exit from the remote server.
- Add an alias entry in your local .bashrc to make the process even simpler.
alias anyname='ssh username@server'
- Restart the Terminal.app
That’s all. Now you should be able to ssh to the remote terminal from your local machine simply by running
on the Terminal.app.
One of the simplest way to compare the folders’ content is to use the diff utility.
Open the Terminal.app (/Applications/Utilities/Terminal.app)
If you want to compare ~/Documents/Oldfolder with ~/Documents/Newfolder,
diff -rq ~/Documents/Oldfolder ~/Documents/Newfolder
Here the r parameter tells the diff to run recursively and q tells it to output the short version of the results.
I am a big fan of the Vim editor for many years. However installing, updating and removing Vim plugins require a great deal of time and effort. In this article I would like to introduce a couple of tools, which makes the whole process a breeze. The basic idea is instead of copying plugin files to different directories, just leave them where they are and load them when Vim starts. To remove a plugin, simply delete the corresponding subdirectory.
- Vim Editor Version 7.0 or higher(Some plugins won’t work with older vim versions)
The last two applications are part of the xCode bundle.
- Before we start, it is probably a good idea to create a backup of the old plugins.
Backup the .vimrc file
- Backup the .vim folder
- Create “bundle” subfolder within .vim folder.
(This is where all the plugin directories will be copied)
- Download the pathogen plugin from https://github.com/tpope/vim-pathogen/
(navigate to .vim directory)
git clone git://github.com/tpope/vim-pathogen.git
(This will download the latest pathogen plugin)
cp -r ~/.vim/vim-pathogen/autoload ~/.vim/
(This will copy the autoload directory to .vim folder)
- To load pathogen when vim starts, add the following lines in .vimrc
filetype plugin indent on
- Remove the vim-pathogen folder.
rm -rf ~/.vim/vim-pathogen
(remove the empty folder)
- The next step is to download all your favourite plugins into the bundle directory and keep them sync with the latest updates. The Ruby script written by Tammer Saleh comes in handy for this purpose. Once you customize the script by including all the plugins you want to use, all you have to do is to run the script in regular intervals.
- Download the latest Ruby script to .vim directory.
The modified ruby script can be downloaded here.
- Open the script and activate your favourite plugins. You can also add new plugins from git, mercurial repositories or even zipped bundles from Vim.org. Once you are ready with the activated collection save the script and run to install.
You can find my own vim setup on GitHub. Download the complete package and customize it as necessary. Please read the README for installation instructions.
- Tim Pope’s pathogen: http://www.vim.org/scripts/script.php?script_id=2332
- Ruby script(Tammer Saleh): https://gist.github.com/593551
If you want to bind an ip address to a host name or block a certain applications from connecting to a specific server address, you can add that information to the hosts file. Here is how you do it.
- Log in as an admin. user.
- Open the Terminal.app located at Applications > Utilities > Terminal.app.
sudo nano /private/etc/hosts
to open the hosts file
- Add the corresponding record.
Eg.: 127.0.0.1 activate.adobe.com
- Press Control+o to save and Control+x to exit the nano editor.
to clear DNS cache.
That’s all. Have fun!
Recently, when I tried to install a pkg file, just by double clicking, it gave an error. In such situations commandline installer tool comes handy. Here is how you can use it.
sudo installer -pkg <pkg name> -target /
(Usually the target location is the root folder. However you can also point it to some other location depending on your requirements)
Here is an example.
sudo installer -pkg ~/Downloads/iStockphotoApertureExport.pkg -target /
Worst thing happened yesterday while I was updating my router(WGR614v9
54 Mbps Wireless Router) firmware. Usually updating the firmware is an easy process. All you have to do is log in to the router via any web browser and upload the latest firmware file. In my case I did manage to upload the file but when the router restarted the power button started blinking. The blinking power button indicates that the firmware is corrupt.
In such a situation only way to save the router is to transfer the firmware file through router’s built-in TFTP server. If you are comfortable with the Terminal.app the process is really easy. Here are the steps.
- Fire-up the Terminal.app (/Applications/Utilities/Terminal.app).
- cd to the location where the firmware file (with .chk extension) is located.
- Issue the following commands and hit return
tftp -e <ip address of your router>
(Command to connect to the tftp server)
(Copy the firmware file from the local machine to the server)
(Quit the tftp connection)
This method worked well with my router. However there may be different ways to transfer the file with other brands.
Recently when I was sitting on my couch in the living room, I have realised that the iTumes running on my iMac (which is in a different room) is playing bit too loud. As it was too comfortable to get up and go to the machine to reduce the volume I found an easy method using the OS X terminal. Here is how I did it.
Connected to the iMac using ssh from my laptop.
Entered the following code
osascript -e 'set volume output volume 10'
Here the volume scale is from 0 to 100.