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.