Tuesday 28 October 2008

Choosing which version of Java JRE system should use

Sometimes a number of various Java Runtime Environment versions is needed to be installed on a Linux system. To chose which one to use as a default use this command:

sudo update-alternatives --config java


An output like this will show up:

There are 6 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-4.3
2 /usr/lib/jvm/java-gcj/jre/bin/java
3 /usr/lib/jvm/java-6-sun/jre/bin/java
* 4 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
+ 5 /usr/lib/jvm/java-6-openjdk/jre/bin/java
6 /usr/bin/gij-4.2

Press enter to keep the default[*], or type selection number:


All to do here is enter the number of the selection next to the alternative JRE name and press enter.

Hope this was helpful. Enjoy.

Schedule fsck program to check disks on next reboot

It's not save to run fsck (file system check) while the disks are mounted. But it can be scheduled to run check on the next reboot simply by creating a file named 'forcefsck' on he root partition. Like this:

$ sudo touch /forcefsck

Friday 19 September 2008

OpenSUSE: Install RPM packages with zypper CLI tool

Open Suse Linux uses RPM packages for software installation. Those files end in .rpm extension.
Most Suse users are familiar with the YaST graphic interface, but sometimes the quicker way to install a RPM package is from command line with the tool named zypper. This tool is similar to apt-get tool that Debian users use to install .deb packages and it uses already configured repositories to fetch packages. I'll explain its basic usage here.
All zypper commands have its longer and readable variant, and its shorter and less readable one. Commands for installing, removing and updating software needs root privileges.

Commands for software management:

Installing software

$ zypper install [package name]
$ zypper in [package name]


Removing software

$ zypper remove [package name]
$ zypper rm [package name]


Updating all installed software

$ zypper update
$ zypper up


Distribution upgrade

$ zypper dist-upgrade
$ zypper dup


Note: All of the above commands require root priviledeges.

Commands for software querying:

Search for packages matching a pattern

$ zypper search [pattern]
$ zypper se [pattern]


Show package information

$ zypper info [package]
$ zypper se [package]


Commands for repository management:

List all repositories

$ zypper repos
$ zypper lr


For all other commands and help type:

$ zypper --help

Wednesday 17 September 2008

Vim feature that makes editing easier

Vim, along with the Emacs is the best free text editing choice in the Linux and OSS world. It has tons of features and improvements that can make text editing a lot easier and faster. I'll mention some of its features on the blog that I use the most.
This post is not a beginners tutorial or guide and I'm assuming that the reader has basic Vim knowledge such as entering/exiting insert mode, basic movement keys etc.
So let's get started.

One word replacement

Let's assume we have this line of text in our file:

Nikola Tesla was tha greatest engineer in tha world


Assume that the Vim is in the command mode and that the cursor is on the letter 'w' of the word 'world' also. This line has two typos in it an that is the 'tha' words. We need to substitute that typos with the right word 'the'. In the Vim editor that is done easily with the simple ex command:

:s/tha/the/g


First letter s of this command means substitute. Expression after the first slash presents the text we need to replace, and the second expression after the second slash presents the text to substitute with. Finally the letter 'g' in this command after the last slash says vim to replace every 'tha' occurrence in the line with the right word 'the'.
But what if we use the above command on this kinda sentence?

Nikola Tesla was tha greatest engineer in thailand


First three letters of the word 'thailand' will be substituted as well; the word 'thailand' is also a typo here cause it needs to start with the capital letter, but ignore that for now. The problem can be fixed with regular expressions that can be used in vim during a text search. Regular expressions are complex topic and I'm not gonna explain them here in depth. Let's just say that \< and \> can be used to mark start and end end of the word respectively, and our ex command would look like this:

:s/\<tha\>/the/g


This command works only on the line in witch cursor resides. To substitute each and every bad occurrence with new in the file this command is used:

:%s/bad/new/g


Read the '%' character as: do the commands on the whole file.
Substitutions that needs to be done from line 1 to 10 for example is used like this:

:1,10s/bad/new/g


Isn't Vim great?

Thursday 11 September 2008

Find command: '-exec' action

There is a way to execute a command on each file using find and it is done with the -exec action argument.

For example, removing all backup files under the '/' directory and its subdirectories is done like this:

$ find / -name '*~' -exec rm '{}' \;


This means: execute rm command on each filename that ends with '~' on file system. The '{}' part of the command is replaced with the filenames that are found during execution, and escaped semicolon (\;) at the end represents the end of the -exec action argument.

Thursday 21 August 2008

openSUSE: Installing flash player plugin on any internet browser

Download Flash Player installer in .tar.gz format from this site. Run these commands in the directory where you saved the archive:

~> tar -xvvzf install_flash_player_9_linux.tar.gz
~> cd install_flash_player_9_linux
~> sudo cp libflashplayer.so /usr/lib/browser-plugins


Enter root's password, restart any running internet browser and that's it. Worked for me for Firefox.

Monday 18 August 2008

Ubuntu: Installing Truetype Fonts (TTF)

To install basic Microsoft TrueType Fonts such as Arial, Courier, Impact, Times New Roman etc. you need to enable the "Universe repositories" and install the msttcorefonts package:

$ sudo apt-get install msttcorefonts


New fonts will appear under the /usr/share/fonts/truetype/msttcorefonts directory.
Truetype fonts can also be installed by simply copying the .ttf files in some subdirectory under the /usr/share/fonts/truetype/.
For example, If you downloaded some neat TTF fonts over the internet, you can install them like this:

neat_fonts$ sudo mkdir /usr/share/fonts/truetype/neat
neat_fonts$ sudo cp *.ttf /usr/share/fonts/truetype/neat


Note: Name the subdirectory under /usr/share/fonts/truetype/ as you wish; "neat" is just for demonstrating purpose

Log out and than login again to be able to use new fonts or just run this command to regenerate the fonts cache:

$ sudo fc-cache -fv


Those fonts will now be accessible to any user on the Ubuntu system.

Wednesday 13 August 2008

How to setup OpenDNS on Linux

Check the OpenDNS webpage for more information of its services. Here, I'll just explain how to configure your network and switch over to the OpenDNS servers.

Use your favorite text editor and open the /etc/resolv.conf file as root and change the nameserver lines to:
nameserver 208.67.222.222
nameserver 208.67.220.220


Now it is needed to flush any cached addresses on the computer. Type this command:
sudo /etc/init.d/networking restart


That will also restart all the networking services.
Check this website to check that you switched. If you get "Oops!" try again. :)

Sunday 10 August 2008

Installing Internet Explorer on Linux / Ubuntu

Someone would ask: "Why would I need IE on Linux cause I got the newest and best browser ever called Firefox already installed?" :)
Sometimes the IE is necessary for web designers working on Linux to test their pages, or to browse sites that don't open in any browser except the IE.
Here I will explain how to install IE7 on Ubuntu box. Actually only the IE7 rendering engine will be installed on IE6 interface. I did this on my Ubuntu Hardy Linux installation, but the procedure should work on any Debian based distro.
Start by adding two new repositories:
$ sudo gedit /etc/apt/sources.list


Add (or uncomment) those two new lines:
deb http://us.archive.ubuntu.com/ubuntu hardy universe
deb http://wine.budgetdedicated.com/apt hardy main


Note: If using Ubuntu Gutsy type gutsy instead hardy in those two lines above.

Next, add the winebudget GPG key and install/upgrade wine and cabextract packages:
$ wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install cabextract wine


Now, download IEs4Linux and install it:
$ wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
$ tar zxvf ies4linux-latest.tar.gz
$ cd ies4linux-*
$ ./ies4linux --hack-ie7-proxy-settings


Check the versions of IE you want to install and also check to install flash plugin. If you get some kinda error try it without flash plugin.
Click Advanced button and check the box at the bottom to install version 7.0. Click OK and than OK again. When the IE6 is installed it will run. You need to configure your proxy settings now in the Internet Options dialog. Once done, close the browser and the installation of IE7 rendering engine should continue.
If the installation of IE7 won't continue try without the proxy hack argument --hack-ie7-proxy-settings.

That's it.

Saturday 9 August 2008

Search & Play YouTube videos in Totem Movie Player / Ubuntu

First think to do is to install appropriate gstreamer plugins. Use the apt-get command:

$ sudo apt-get install gstreamer0.10-plugins-bad


Next, open up the Totem Movie Player. You can start it with the totem & command in the CLI (command line interface) or from the desktop menu. On Ubuntu it can be found under Application -> Sound & Video -> Movie Player. If you don't have Totem install it the usual way of installing software packages.
Under the player's Edit.. menu select Plugins... New window will pop and under it check the box next to YouTube browser. The new sidebar should become visible. Something like this:



It is also possible to install YouTube H.264 plugin for better quality. Download archive file from here, and extract the files in the:

/usr/lib/totem/plugins

enjoy.

apt-get command

Most Debian Linux are already familiar with the apt-get command. For those unfamiliar with it here's a short description.

apt-get is a command-line tool for handling Debian Linux packages and it is used to install/remove individual packages, upgrade packages, apply patches, upgrade debian distribution, download .deb files etc. This command is a frontend to manyy GUI applications such as "Synaptic Package Manager"

Install or upgrade package

$ apt-get install [package name]


Remove a package

$ apt-get remove [package name]


Remove a package and its configuration files

Use this if 100% sure that the package will not be used never again :)

$ apt-get --purge remove [package name]


Upgrade a package

This will list all possible software upgrades. If you wish to upgrade them all hit the 'y' key:

$ apt-get upgrade


To upgrade single package use the 'install' argument option.

Distribution upgrade

Intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.

$ apt-get dist-upgrade


note: use auto-complete command line feature if you don't know full package name. It is done using the <TAB> key.

Tuesday 29 July 2008

Installing Apache2 server with PHP and MySQL support

Today I wanted to try out and start learning PHP scripting language a bit. PHP is server-side scripting language so for it to work I need a server that supports it. Apache web server is widely used with PHP so I'm going for that combo. Also, I would like to have a MySQL database support.
Here's how I did that on Ubuntu 8.04 LTS. Googling around I found that the wanted combo is named LAMP (Linux-Apache-MySQL-PHP) task and it can be installed using tasksel command:
sudo tasksel install lamp-server


But unfortunately it gave me an error:
tasksel: aptitude failed (100)


Is it a bug or something wrong with my machine? Anyone has an answer please comment.
So I turned to the good old apt-get:
sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql


After the installation you'll be asked for MySQL 'root' user password. Enter it and don't forget! :) Now, the Apache server can be started with:
$ sudo /etc/init.d/apache2 start
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName


To hide this strange "Could not... " message you need to create a file /etc/apache2/conf.d/fqdn and put this line in it:
ServerName localhost


Now to check functionality create a 'test.php' in the /var/www/ directory with the line:
<?php phpinfo();?>


Open up your browser and type http://localhost/test.php in the address bar. If you get something like this:



you did it!
For configuring databases, user privileges etc. there is an application called "phpmyadmin" that really ease the job.

Wednesday 9 July 2008

Mounting bin/cue files in Linux

It's impossible to mount .bin/.cue files in Linux with the 'mount' command. Bin/cue files always come in pairs; bin file is the raw image of a cd, and the cue file specifies the mode in which a cd is written and the number of bytes per sector in the image (bin) file.
There are two methods for mounting bin/cue files. First is to convert bin/cue file to iso than burn it, and the second is to try mounting it directly with some other software tools.

Converting to iso with bchunk

One of the commands for converting bin/cue image to .iso image is bchunk. If you don't have it installed already type:
sudo apt-get install bchunk

Now, to convert it to iso type:
bchunk -v image.bin image.cue <basename>

And now, when the conversation is done mount an iso file:
mount -o loop,ro -t iso9660 <filename>.iso <mountpoint>

Some other tools

CDfs - download - cdfs is a file system kernel module. You can use it instead of iso9660 when you mount cds. It will show all the tracks on a cd as files in the mounted directory, i.e. A data cd may show a single .iso file, an audio cd will show some .wav files, and a mixed cd may show an .iso file and an apple hfs image, and some .wav files.

cdemu - homepage - Userspace CDEmu is a CD/DVD-ROM device emulator for linux, licensed under GPL v2 or later.

Enjoy!

Thursday 3 July 2008

Symbolic Links vs. Hard Links

Many times, it is required that two or more applications have access to the same file somewhere on the file system. Microsoft users are familiar with those kinda files named icons that point to another directory or a file physically written on disk so when users run it, they actually run the file that icon points to. Links in Linux function that way, as a pointer to physical data. There are two kinds of links in Linux: hard links and symbolic links.
On most system all file names are hard links. The name of the file is just a name that refers to the actual data stored on the disk. It is possible to create multiple names (hard links) for the same data stored on the disk, so the data stored on the disk can be modified from different locations. Simply put, if one hard link is modified, all hard links (including the original file) is modified. Hard links on Linux are made with the ln command. If the file '.myconf' allready exists, to create a hard link named '.conf' we'll write:
ln /path/to/.myconf /path/to/.conf

If '.conf' is modified, '.myconf' is modified as well. All hard links pointing to same original file have same characteristics of that file such as, amount of disk space used, file permissions and so on. Drawback of hard link is that it is hard to make a difference between it and the real file because they show all real file characteristics. Also, all hard links need to be located on the same filesystem.
Symbolic links serves the same purpose as hard links, but they only contain a path to original file, not all characteristics of a file, so they are easy to differentiate. To create symbolic link type:
ln -s /path/to/original/file /path/to/symlink

Symbolic links are more used than hard links.

Monday 30 June 2008

Customizing BASH command prompt

The prompt text can hold more information than just username and hostname, such as command numbers, time, date, shell version etc.
The text for the prompt is held in environment variable PS1 (Prompt String 1), and all that needs to be done is to change that variable.
Default prompt on most Linux systems consists of username, hostname and current working directory, something like this:
username@hostname:~$ 

The prompt is fully customizable and the PS1 variable can be changed to users needs. We can have either extra short prompt with just one symbol, or a very long one showing all sorts of information in all sorts of colors. Simple example would be prompt consisting of simple series of characters, for example a 'my prompt: ' character. So we assign a new value to PS1:
tvrtko@tvrtko-laptop:~$ PS1='my prompt: '
my prompt:
my prompt:

Prompt string can have a wide range of characters, escaped control sequence characters and color codes.
Here are bash escaped control sequence characters:

* \a : an ASCII bell character (07)
* \d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
* \D{format} : the format is passed to strftime and than passed to the prompt
* \e : an ASCII escape character (033)
* \h : the hostname up to the first '.'
* \H : the hostname
* \j : the number of jobs currently managed by the shell
* \l : the basename of the shell’s terminal device name
* \n : newline
* \r : carriage return
* \s : the name of the shell, the basename of $0 (the portion following the final slash)
* \t : the current time in 24-hour HH:MM:SS format
* \T : the current time in 12-hour HH:MM:SS format
* \@ : the current time in 12-hour am/pm format
* \A : the current time in 24-hour HH:MM format
* \u : the username of the current user
* \v : the version of bash (e.g., 2.00)
* \V : the release of bash, version + patch level (e.g., 2.00.0)
* \w : the current working directory, with $HOME abbreviated with a tilde
* \W : the basename of the current working directory, with $HOME abbreviated with a tilde
* \! : the history number of this command
* \# : the command number of this command
* \$ : if the effective UID is 0, a #, otherwise a $
* \nnn : the character corresponding to the octal number nnn
* \\ : a backslash
* \[ : begin a sequence of non-printing characters
* \] : end a sequence of non-printing characters

Now lets set a prompt displaying current time in 12-hour format, username, the command number and the '$' sign at the end:
my prompt: PS1='\T-\u-\# $ '
10:22:28-tvrtko-4 $
10:22:32-tvrtko-4 $ ls -a
...
10:22:38-tvrtko-5 $

How to add colors to a prompt?

This might look a little complicated at start but its really not a big deal. To add colors to the shell prompt use the following export command syntax:
'\e[x;ym $PS1 \e[0m'
Where:
* \e[ - Start color scheme
* x;y - Color pair to use (x - foreground;y - background)
* $PS1 - your shell prompt
* \e[0m - Stop color scheme

foreground colors:
* 30 black
* 31 red
* 32 green
* 33 brown
* 34 blue
* 35 purple
* 36 light
* 37 gray

background colors:
* 40 black
* 41 red
* 42 green
* 43 brown
* 44 blue
* 45 purple
* 46 light blue
* 47 white

Now lets set the new color prompt with light blue background displaying 24hr - time in black, username in brown and the '$' sign in black again:



Notice that the \e[0m end sequence brings back the default color. To set text after the prompt in brown foreground and black background we would end sequence with \e[33;40m.
To make prompt string effective every time bash starts put your PS1='...' line in .bashrc file.

Well, I hope this guide was clear to understand. Have fun.

Thursday 19 June 2008

How to start a script at boot time

Making script start at the boot time is really not a big deal, it's done with ease with a few commands and actually no knowledge about system runlevels is required for simple tasks. But a little background info won't hurt.Runlevel is a state or mode in which system works, and each runlevel uses its own specific services/scripts. Usually there are 8 of them:

* 0 System Halt
* 1 Single user
* 2 Full multi-user mode (Default)
* 3-5 Same as 2
* 6 System Reboot

There is also runlevel called "s" which is used by the system when it changes runlevels.
Default runlevel for a Linux based system is 2 generally. Finding out in which runlevel system resides is done running 'runlevel' command as root
$ sudo runlevel
[sudo] password for tvrtko:
N 2

Number 2 means system is in runlevel 2 and the N character means 'None' - system was in that runlevel since boot.
For each runlevel there is a directory filled with needed scripts in /etc. On Debian/Ubuntu systems these directories are called: rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d and rc6.d, and if you open one of them you'll see all those scripts with weird names that are actually just links to real scripts that reside in /etc/init.d directory. Command update-rc.d makes those links, and I will explain its most basic usage.

Suppose I have a script named "myfirewall" filled with lots of commands needed to configure my network and protection, and I need to start it every time the system boots. This script must reside in /etc/init.d directory for this to work, and it must be executable.
$ chmod 755 /etc/init.d/myfirewall

All that it must be now is to run update-rc.d command like this:
$ sudo update-rc.d myfirewall defaults
password:
Adding system startup for /etc/init.d/myfirewall ...
/etc/rc0.d/K20myfirewall -> ../init.d/myfirewall
/etc/rc1.d/K20myfirewall -> ../init.d/myfirewall
/etc/rc6.d/K20myfirewall -> ../init.d/myfirewall
/etc/rc2.d/S20myfirewall -> ../init.d/myfirewall
/etc/rc3.d/S20myfirewall -> ../init.d/myfirewall
/etc/rc4.d/S20myfirewall -> ../init.d/myfirewall
/etc/rc5.d/S20myfirewall -> ../init.d/myfirewall

And that's it. The script will run for every runlevel now. Notice the script will run as root user. If you need to run some service as a less privileged user simply create a script in /etc/init.d with the line:
su [username_you_want_as_owner] -c /path/to/program

To remove script from startup sequence:
$ update-rc.d -f  myfirewall remove

This should be enough for a start.

Wednesday 18 June 2008

Linux Command: alias

The alias command is used for creating shorter meaningful synonyms for longer, complex and sometimes meaningless shell commands.
Few years ago when I started being interested in all 'free' and 'open' things that Linux OS gives I also started being more an more frustrated typing some commands over and over again. Than I descovered aliases. Oh lucky me.
Most of advanced or even beginner Linux users already know this, but those that don't will find it quite handy in future.
Syntax goes like this:
alias [synonym]='[true shell command]'

Real examples might be:
alias lsa='ls -all -F'

Now if lsa is typed in a shell it will automatically run command ls -all -F. Saves so much typing.
Aliases are most efficient if they are defined at a shell startup time. To do that all that's needed is to put the line at the end of your bash profile file which is usually full of commands that run at shell startup and user mostly don't even know or think about it. Look for the file named '.bashrc', '.bash-profile' or simply '.profile' in your home directory.

Tuesday 10 June 2008

Renaming multiple files with 'rename' command

The syntax for the rename command is:

rename [ -v ] [ -n ] [ -f ] perl_expression [ files ]

to rename for example multiple photo files with '.JPG' extension to '.jpg' extension:

rename -v ’s/\.JPG$/\.jpg/’ *.JPG

The perl substitution for regular expression syntax is: s/old/new/.
s means 'substitute'. Period character substitutes any character, but in this case it's not wanted and we need to escape it with '\'.

Tuesday 3 June 2008

Downloading files from a cell-phone via Bluetooth

This is a guide for downloading files from a cell-phone to a linux pc from a terminal.
First thing to do is to activate a bluetooth adapter on both pc and a cellphone and make it visible and accessible. The necessery software must be installed too:
apt-get install obexftp bluetooth

First command is for scanning bluetooth enabled devices in range to get their address. Something like this:
tvrtko@tvrtko-laptop:~$ hcitool scan
Scanning ...
00:15:B9:9D:40:39 SGH-ZV10 t

Command for browsing appropriate channel for file transfers:
tvrtko@tvrtko-laptop:~$ sdptool browse 00:15:B9:9D:40:39
Browsing 00:15:B9:9D:40:39 ...
Service Name: QC Voice Gateway
Service RecHandle: 0x10000
Service Class ID List:
"Headset Audio Gateway" (0x1112)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 3
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Headset" (0x1108)
Version: 0x0100

Service Name: QC Voice Gateway
Service RecHandle: 0x10001
Service Class ID List:
"Handfree Audio Gateway" (0x111f)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 4
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Handsfree" (0x111e)
Version: 0x0101

Service Name: FTP
Service RecHandle: 0x10002
Service Class ID List:
"OBEX File Transfer" (0x1106)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 16
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX File Transfer" (0x1106)
Version: 0x0100

Service Name: OPP
Service RecHandle: 0x10003
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 17
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100

Service Name: Serial Port
Service RecHandle: 0x10004
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 18
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Serial Port" (0x1101)

Service Name: Dial-up Networking
Service RecHandle: 0x10005
Service Class ID List:
"Dialup Networking" (0x1103)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 8
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Dialup Networking" (0x1103)
Version: 0x0100


Our channel of interest is 16. Bellow Service Class ID List: "OBEX File Transfer" lines.

To browse files on a cellphone use the command to gat folder listing (in my case it is in XML format):
tvrtko@tvrtko-laptop:~$ obexftp -b 00:15:B9:9D:40:39 -c / -l
Browsing 00:15:B9:9D:40:39 ...
Channel: 16
Connecting...done
Sending ""... done
Receiving "(null)"...\

(folder listing here)

Disconnecting...done

And now, to download your newly taken photo you need to type command similar to this:
tvrtko@tvrtko-laptop:~$ obexftp -b 00:15:B9:9D:40:39 -c /Pictures -g Photo-0062.jpg
Browsing 00:15:B9:9D:40:39 ...
Channel: 16
Connecting...done
....
....

For uploading files use this command:
obexftp -b 00:15:B9:9D:40:39 -c /Pictures -p Photo-0063.jpg

NOTICE: Use right addresses, folder and filename specific for your cellphone

Tuesday 22 April 2008

Ubuntu: Use root password instead default user password

After clean install of Ubuntu, you noticed u have to enter your user password to do administrative or system tasks. This is the way to change it.
First make sure u set password for the 'root' user:
sudo passwd root

Use your favorite text editor and edit '/usr/share/gconf/defaults/10_libgksu' file.
Change:
/apps/gksu/sudo-mode true

to:
/apps/gksu/sudo-mode false

Then issue following command:
sudo update-gconf-defaults

Saturday 12 April 2008

Fixing large fonts / graphics bug on Linux with intel driver

Problem with Intel drivers on linux which manifests like this: Click to see screen shot is easily fixed by adding this into /etc/X11/xorg.conf file:

Section "Monitor"
... #whatevert was in already.
Option "DDC" "no"
EndSection

Tuesday 8 April 2008

HOWTO: compress and extract rar archives under linux

Quick how-to on extracting and compressing .rar archives. For this method it is essential that u have WinRar, hopefully installed on your windows partition.

1. Install wine. You can do it with Synaptic Package Manager under Debian
2. Copy 'rar.exe' from the directory where the WinRar is installed on windows partition to '$HOME/.wine/drive_c/windows/system32' on your linux system. If you don't have WinRar u should probably buy it :)
3. Now you can call rar comand with 'wine rar '. Type 'wine rar -h' for help.
4. Enjoy typing

It's possible to run WinRar GUI with wine, so that is another option, but I think this is quicker method.

Wednesday 2 April 2008

Tutorial - Adding new user to your Linux system

In this post I will try to explain basic usage of commands considering user and group administration on Linux systems such as adding/deleting a user or groups, setting permissions and so on. Only superuser (root) is allowed for user/group administration so you'll need to login as a root user with the 'su' command. On my shell its like this:

~$ su
Password:
#


Perhaps its needed to add a new user for new person that needs to work on the system, or you will need to add a user and a group for some software package to work securely. Creating user or updating user information is done with the 'useradd' command. So let say I need to create new account for my mother who just found out how cool is Linux. Her username will be 'mom' and I'm gonna add her on the system now:

# useradd mom
# cat /etc/passwd | grep mom
mom:x:1001:1001::/home/mom:/bin/


With this command I simply added new user called 'mom'. Secondly I wanted to check out did it accualy succeed with the second command. Yes, mom is added in the '/etc/passwd' file. But what about hose other data? Every entry in 'passwd' file means is formated as:

[account name]:[password]:[user ID / UID]:[group ID / GID]:[home directory]:[shell]


We see that her UID and GID are both 1001, these numbers are unique to user 'mom' and her initial group (which is also called 'mom'). Mom's home directory is '/home/mom. The last parameter is the type of shell she'll use, in this case 'sh'.
Letter 'x' means the password is encrypted. But what is actually her password? I didn't type any password when creating account. Her password was randomly generated cause I didn't specify it, and I actually don't know it. But thats no problem, cause I know root password, and I can change any password for any user anytime with 'passwd' command. I'll do it now for mom:

# passwd mom
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


Now any user that knows her password can login to her account with 'su mom' command.
Now I'm noticing one other thing. I cannot go to moms home directory cause it doesn't exist, and I need to create one for her. I'll do it with this command:

# mkdir /home/mom
# chown mom /home/mom
# chgrp mom /home/mom


Now mom has her own directory in which she can put her stuff. Directory 'mom' also belongs to her 'mom' group. But I could have saved myself from the trouble if I just put '-m' option when creating her account like this:

# useradd -m mom


The 'm' option automatically creates user directory.
The process of creating a new user is over, I'll just change her default shell to 'bash' and change my file permissions so she can't digg through my files:

# usermod -s /bin/bash mom
# exit
exit
~$ cd ..
~$ chmod o= tvrtko


For further details of a particular command see the 'man' pages.

Monday 31 March 2008

Simple python script for extracting various archive types

Last couple of days I've been compiling lots of software from source and i got very annoyed typing the tar command over and over again so I created simple python script for this purpose. Now I can extract .tar, .tar.gz, .tar.bz2 and .zip archives with just one command. Of course it could be maybe done better with bash and aliases but i wanted to try out python.
Here's the script:unpack script
And the whole code:

#!/usr/bin/env python
#
# simple python script for extracting mostly used types of archives
# this script extracts .tar, .tar.gz, .tar.bz2, .gz and .zip archives
#

import sys # required for fetching command line arguments
import os # required for calling commands for archive extracting

def unpack(s): # this is definition of depack
if (s.find('.tar.gz') != -1): # function. It takes string
os.system("tar -xvvzf " + filename) # filename as argument.
elif (s.find('.tar.bz2') != -1): # functon than calls
os.system("tar -xvvjf " + filename) # appropriate command according
elif (s.find('.tar') != -1): # to file extension
os.system("tar -xvvf " + filename)
elif (s.find('.gz') != -1):
os.system("gunzip" + filename)
elif (s.find('.zip') != -1):
os.system("unzip " + filename)
else: print "Wrong archive or filename" # other types not supported

try: # this is main program
filename = sys.argv[1] # first argument right after
unpack(filename) # 'unpack' command goes in the
except IndexError: # filename string
print "Filename is invalid!" # than the depack function is called

# try-except block is used for handling IndexError exception if no argument is passed

Usage:
./unpack [archive filename]

Sunday 30 March 2008

Cleaning your Debian linux box

Recently i ran out of disk space on my linux partition and i wanted to clean it up to free some space. I knew for sure that junk files exists but wasn't completely sure what files i can remove to keep system from broking. Once again google comes into play. Here is a short description of how to clean up the mess! Im using Debian etch for this walk-through. This is actually just a little reminder.

1. Cleaning residual config packages

Open up Synaptic Package Manager under Desktop -> Administration and enter root password. Under 'Status' filters (lower left part of the screen) select 'residual config', mark all packages, right click and select 'Mark for completely removal' and click apply button.

2. Removing partial packages

Open up terminal and type:

# sudo apt-get autoclean

3. Unnecessary locale data

Just install 'localepurge' package and after installing anything this script will remove unnecessary locale data, all but the ones you selected not to.

4. Removing orphaned packages

Install 'deborphan' package. In Synaptic Package Manager under select 'Filters' under Settings menu, create a new filter and on the right deselect all checkboxes but leave the one that says 'Orphaned' unchecked. Now select this new filter under 'Costum filters' selection and u may remove all those packages.

Thursday 27 March 2008

Installing Debian linux over internet / without cd-rom / netboot

I ordered my kubuntu cd copy, but I wasn't patient enough to wait for it 4-5 weeks so I googled around and found useful tutorials of how to install linux without a cd. Here's the link that explains everything: Large HOWTO

But I decided to write a shorten version mostly just to have my own little reminder if that link gets lost somewhere.
...Googled more around to find interesting distribution. Already had ubuntu installed so decided to go for Debian-sid.

Here are the steps:

1. Get "linux" installer kernel and "initrd.gz" ramdisk from here: Debian Sid netboot mirror and save those two files in c:\boot folder

2. Get Grub4Dos from sourceforge and unpack "menu.lst" and "gldr" files to c:\

3. Append this line at the end of your c:\boot.ini file:

C:\grldr="Start GRUB"

4. Open "menu.lst" file with text editor end append this at the end:

title Debian installer
kernel (hd0,0)/boot/linux ramdisk_size=10934 root=/dev/rd/0 devfs=mount,dall rw --
initrd (hd0,0)/boot/initrd.gz


5. Restart computer and instead booting windows select "Debian installer", and the installation starts.

Quite easy! This procedure can be done for many linux distros. You just need to put those two files (from step 1) of your favourite distro in c:\boot directory and that's it.