Showing posts with label Linux-tips. Show all posts
Showing posts with label Linux-tips. Show all posts

May 24, 2009

Bluk rename files in Linux

Today one of my friend asked me to bulk rename all files in a folder. He had a collection of songs named randomly with no extension. He also wanted to add the extension, mp3 in all files(Yes, he was sure about the encoding)
I opened a terminal in that folder and executed the following command.
NUM=1
for SONG in ./*
do
mv $SONG song$NUM.mp3
let NUM=NUM+1
done

So lets peek what the above script does:
  1. Defined a variable NUM and initialized it with 1.
  2. Defined a foreach loop. Here for each files in current path the for loop is executed.
  3. Rename(move) the file $SONG to song<num>.mp3
  4. Increase the value of variable NUM by 1.
  5. end. ;)
So if you want to rename in a different fashion you can hack the line mv $SONG song$NUM.mp3 in any way you like. But Remember the second argument to the mv command must vary for each loop, otherwise you will end up deleting all files except the last one.

Jan 5, 2009

Search with single click

Searching cant be any more easy than this.Just select and click.
Here is how you can search anything you select with just a single click.
First install this package "googlizer"
apt-get install googlizer

Just drag it to the panel(from Applications->Internet) for easy access and enjoy.
Select any text anywhere and just click on it.

You can even use it with other links.. May be answers.com or wikipedia.org. Here's, how you do it.

Right click on the googlizer button on the panel and open its properties. And in the command text area type the following to convert it to answerizer ;)
googlizer -u "http://www.answers.com/topic/"

If you want to look it better click on the googlizer Icon at the top left of the properties dialog and change it as you want.

The core thing that the googlizer does is just copies the text in X'selection and appends it to the end of the link that you provide, and finally opens it in Browser. If you do not provide any link then it uses "http://www.google.com/search?q=".


For Wikipedia-izer, whatsoever,
googlizer -u "http://en.wikipedia.org/wiki/"


*Please leave in comment if you use it for any other.

Jun 5, 2008

Removing the login message.

I dont know about you, but i dont like the message like "... you have new message ...." that is shown after logging in.
If you are like me and want to remove the message. Follow the following procedure. Its pretty simple:

Just create a file named ".hushlogin" in the home directory of the current user.
$ touch .hushlogin

If you want to hide this message for each new user that is created you can create the file named ".hushlogin" in /etc/skel directory.

# touch /etc/skel/.hushlogin

Remember you need root access in the second case.

Dec 7, 2007

Shortcuts in Terminal (console)

Must of use face the problem with cutting and pasting in terminal... I know it because i did felt it a few days back too.
I don't know how but it was my luck that that i pressed ctrl+l insted of shift+l. I got amazed when i saw it cleared my console .. OMG it was a short to clear the terminal screen...

Soon after that i tested with each combination and here are the shortcuts that i found working...

ctrl+L = clear the screen
ctrl+W = clear the current word
ctrl+K = clears everything after the current curser position
ctrl+T = swaps last two letters
ctrl+U = cut
ctrl+Y = paste
ctrl+I = autocomplete (similar to pressing tab-key)
ctrl+P = Previous command (similar to pressing up-arrow)
ctrl+A = Move the cursor to the begenning
ctrl+D = same as what DEL-key does
ctrl+H = same as what BACKSPACE-Key does

...

please comment if you have any more...

Nov 25, 2007

Opening file as root with just few clicks...

[I tested it in ubuntu]
For basic user, I hope need not to go to terminal for any of of the region beside editing a file as root. You might feel bored about this. Here's a handy shortcut... ( yea, you wont need to go to terminal each time.)

First goto to the following directory create a file.
/home/<current_user>/.gnome2/nautilus-scripts

create a file with name "Open as root"
and copy and paste all this code into the file:
for a in $NAUTILUS_SCRIPT_SELECTED_URIS; do
gksudo "gnome-open $a" &
done


and save that.


and its done...

Right click on any file/ folder while browsing from "nautilus" and goto the Scripts menu and select "Open as root" .... give your password to open it.

Note: You should be in sudo-ers list to accomplish this.