Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, October 24, 2009

Boot existing Vista from virtualbox on ubuntu

this is a great tutorial on how to do this http://www.qc4blog.com/?p=483

Tuesday, October 20, 2009

mpeg2encode on debian/ubuntu

Have ever waited for a lot of time on convert *.jpg output.mpeg and then it told you convert: Delegate failed `"mpeg2encode" "%i" "%o"' .. dahhhh

get mpeg2encode from here http://www.mpeg.org/pub_ftp/mpeg/mssg/mpeg2vidcodec_v12.tar.gz untar, make and you are done!

Thursday, February 12, 2009

some netstat

to show active connections
netstat -nat


to show open ports
netstate -tulp


will have some more of these later!

Wednesday, October 1, 2008

Latex Figure and \label

Always put the label after the caption, otherwise floats wont be referenced in text !!!!

just ridiculous :s

Sunday, July 27, 2008

clear fonts on ubuntu

http://ubuntuforums.org/showthread.php?t=208396

Sunday, June 29, 2008

Adding a line at EOF to a bunch of files at once

Some people use horrible IDE's to write some horrible C/C++ code that will give many nasty warnings in gcc/g++ because of a missing line at the end of file

here is how to add a line to the end of each file


for f in `find . -type f | grep ^.*.c`; do echo -e "\n" >> $f; done


It could be a more sophisticated line of bash, but this will do for the mean time

Saturday, May 10, 2008

Installing Matlab on Linux

Unfortunately, Matlab is not free!! and i currently only have Matlab 7 R14 student version. In any case we'll install Matlab on linux..

step 1: insert the CD into the CD-ROM
step 2: go to /media/cdrom (that is in ubuntu)
step 3: sudo ./install_unix.sh
this will run a "nice" installer, it'll prompt you for a root directory for matlab files. If you keep your /home partition separate from the / partition then install matlab somewhere in /home so you don't have to install it every time you feel like getting a new linux version, otherwise /usr/local/matlab sounds like a good choice.
The script will also ask you if you want to create symlinks in /usr/local/bin or whatever directory in the $PATH, it is a good idea to say 'y' so that you don't have to put the full path name every time you feel like Matlabing :)
step 4: install gawk so Matlab will hopefully work, and you also should have java installed preferably java-sun, not the gcj; sudo apt-get install gawk
step 5: go to where ever you installed matalb, say /usr/local/matlab and enter the bin directory /usr/local/matlab/bin and run ./matlab this will ask you for the serial number, enter your serial number and enjoy Matlabing for the rest of the night!!
* Notice that a "student license" is only good for one computer :(

Have fun!

Friday, January 4, 2008

Static IP address in Linux

There are many occasions in which you might like to have a static ip address for you machine instead of the one generated dynamically by the router.. Maybe you want to run a webserver, or ftp server, or maybe want to SSH to your machine from any place.. Then you need to now the IP address of the machine, which is not very easy if you are not in the local network... i'm bored of reasons.. let's get to the point:

To assign ur machine a static ip address do this:

Edit /etc/network/interfaces
to have this:

auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.10
network 192.168.1.0
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255

Then, restart networking

sudo /etc/init.d/networking restart

And check the new address by

ifconfig eth0 | grep "inet addr"


Done!!

Change the Default Gnome Terminal size

Gnome terminal comes really small (80x24) which is really small. Further, the GUI provided with it does not let you change the default size easily. So, you have two options:
  1. Keep changing the size manually with the mouse every time you launch a terminal (because Gnome terminal doesn't save its size)
  2. Look for those configuration file and change them
We'll do option 2, apparently option 1 is silly, boring and counter productive.

Gnome terminal follows termcap specifications, so you should find your xterm termcap file and edit it. (We'll get back to what a termcap is in some other posts)

The file in Ubuntu and most other distros is found in
/usr/share/vte/termcap
you'll find this in the file:
:co#80:it#8:li#24:\
change whatever after co# and li# to your desired settings
for me i love this one
:co#90:it#8:li#26:\

And restart you machine..
Done!!!

Other possibilities are also available..
One thing you can do is to right click on the Gnome Terminal launcher in your Gnome Panel and chose properties, which look like something like this:
Then add this next to "Command" --geometry 90x26, so you'll get this:
And this will work also...
At the end of the day, you have permanently changed the Gnome terminal size :)

... Done!!!

Restore your linux

Well.. let's go format Windows... thanks to the nice virus, but this will erase my ubuntu from MBR and I'll not be able to boot into it..
So, after installing windows and wiping out the windows partition. You get the ubuntu live CD and do the following:
sudo grub
find /boot/grub/stage1
This will tell you where are the boot files, something like hd0 or sda1, so you use that in the next step
root (hda0, 1)
setup (hda0)
quit
Remove the liveCD && restart your machine

Now you have a fully functioning Linux partition, if you haven't wiped it out accidentally while reinstalling windows.

More stuff in here:
http://ubuntuforums.org/showthread.php?t=224351

Saturday, December 29, 2007

Find images of certain size and copy them to some directory

Let us say you wanna find images of width 640 so you copy them to a separate directory for further processing. How can you do that?
Here is one way to do it
First, you have to find out the files with width 640. Second, copy them.

To find out file of certain size you can use the command identify

$ identify 0100.jpg
0100.jpg JPEG 378x251 PseudoClass 256c 9kb

Now, when u do
$ identify*.jpg | grep 640
new_0100-0.jpg[451] JPEG 640x425 PseudoClass 256c 16kb
new_0101-0.jpg[453] JPEG 640x425 PseudoClass 256c 22kb
new_0102-0.jpg[455] JPEG 640x425 PseudoClass 256c 24kb
new_0103-0.jpg[457] JPEG 640x425 PseudoClass 256c 26kb
new_0104-0.jpg[459] JPEG 640x425 PseudoClass 256c 12kb
new_0105-0.jpg[461] JPEG 640x425 PseudoClass 256c 23kb
new_0106-0.jpg[463] JPEG 640x425 PseudoClass 256c 20kb
new_0107-0.jpg[465] JPEG 640x425 PseudoClass 256c 24kb
new_0108-0.jpg[467] JPEG 640x425 PseudoClass 256c 17kb
new_0109-0.jpg[469] JPEG 640x425 PseudoClass 256c 28kb
new_0110-0.jpg[471] JPEG 640x425 PseudoClass 256c 31kb
new_0111-0.jpg[473] JPEG 640x425 PseudoClass 256c 36kb
new_0112-0.jpg[475] JPEG 640x425 PseudoClass 256c 27kb
new_0113-0.jpg[477] JPEG 640x425 PseudoClass 256c 25kb

so we do this and save the output in the file files
identify *.jpg | grep 640 | cut -f 1 -d [ > files

Finally
for i in `cat files`; do cp $i directory_640/; done

Thursday, December 27, 2007

Renaming or changing extension of multiple files at once

In a lot of time you want to rename multiple files at once, or maybe change their extension. My Sony camera names files with the extension .JPG which is really annoying!!! I'd love to have it as .jpg or maybe something else. Further, the camera naming scheme is DSCxxxx.JPG where xxxx is for the number of the image, and I'd like to have some custom name instead. So, how to do this?

First, let us start off with an introduction about file naming and shell scripts. Mass file renaming is a pretty common task among everybody and a lot of people do it in many situations, such as the Sony camera situation, or maybe you have so many files in one directory what you want to rename to something else. Examples of these cases are endless, so let us start with file renaming and some of the available tools to do that without wasting time discussing situations.

The BASH shell provides many useful tools for renaming multiple files. Please note that I'm not claiming that BASH shell is the best. I think that the Z shell might provide more tools, but it is so complex for me :)
One tool you can use in bash to rename multiple files is combining the UNIX command mv with a for loop like this:
for file in .; do mv $file hello; done
well... this is not useful.. in face this is disastrous this will rename all files in the current directory to hello, not only this, but also you'll have one file in that directory called hello. Poor you, nothing left to celebrate, no more old memories and nice moments taken by camera, because you've formatted your memory stick :) So let's not do this at all.

Alright, let's say you just want to rename all files in the current directory to holiday_xxxx.jpg, where xxxx is the serial number for a photo, starting from 0000 up to 9999 (of FFFF if your prefer hex)
Let us do that

#!/bin/bash
prefix="holiday"
i=0
for file in *.jpg; do
num=`printf "%.4d" "$i"`
let "i += 1"
mv $file "$prefix_$num.jpg"
done

And that is it we are done. We can also take the prefix as a command line argument and thus use this script in any place where we want to rename jpg photos:
#!/bin/bash
if [ -z "$1" ]; then
echo "please supply a prefix(name) argument"
exit
fi

prefix="$1"
i=0
for file in *.jpg; do
num=`printf "%.4d" "$i"`
let "i += 1"
mv $file "$prefix_$num.jpg"
done

Cool.. now let's explore another tool.. basename. You can use basename like in situations like this:
nitro$ basename /usr/bin/perl
nitro$ perl

Another useful use is when you supply a suffix to basename like this
nitro$ basename hello.jpg .jpg
nitro$ hello
nitro$ basename hello.jpg jpg
nitro$ hello.
nitro$ basename hello.jpg g
nitro$ hello.jp

So, to lowercase a lot of .JPG file you can do this:
nitro$ for file in *.JPG; do mv $file "`basename $file .JPG`.jpg"; done

in my opinion, the easiest is this one, which is using the built in bash variable substitution
for file in *.JPG; do mv $file ${file/.JPG}.jpg; done

Some good source to look @ http://www.debian-administration.org/articles/150

Tuesday, December 25, 2007

Revoming Empty Directories

http://www.cyberciti.biz/faq/linux-how-do-i-remove-all-empty-directories/

cleanlinks

Listing directories only

Some times we need to see only directories... and, as usual, there are a lot of ways to do this..

you can write a quick bash script like this:

for file in *; do if [ -d $file ]; then echo $file; fi; done

This will display, in columns, all subdirectories under the directory you are in.

In GNU it is really simple, you just do this
ls -d */

Now to display each entry on a line you can do this:
ls -d */ | less

or to avoid the 'q' to exit less, then u do this:
ls -d */ | cut -f 1 -d /

To get the effect of ls -l for directories only you can do this:
ls -l | egrep ^d

And you can have more fun, by piping to sort or something else
like
ls -d */ | cut -f 1 -d / | sort -r
which sorts things in reverse order

World Have fun :)

Sunday, December 23, 2007

NetworkManager things

when stuck you can
pkill NetworkManagerDispatcher
sudp pkill NetworkManager
sudo NetworkManager
sudo NetworkManagerDispatcher

and this is good too
iwlist scan

ok.. this was a silly post :) sorry world :P

Turning off IPv6 in ubuntu for faster life

edit /etc/modprobe.d/aliases

comment this
alias net-pf-10 ivp6
#alias net-pf-10 ivp6

then we put these lines somewhere in the file

alias net-pf-10 ipv6 off
alias net-pf-10 off
alias ivp6 off