home | lab | find me | science | publications | software | toolbox | site map

Tips from an Ubuntu user

Centered mostly around Ubuntu, dwm and gnome, which is what I use, and also a few applications such as Blender.

Hide/Show the desktop icons in gnome


Do it by launching gconf-editor and navigating the tree to apps - nautilus - preferences and unticking the box for show_desktop, or from a shell:

gconftool --type boolean --set /apps/nautilus/preferences/show_desktop false

Changing the desktop background from a shell, for gnome

gconftool --type string --set /desktop/gnome/background/picture_filename "/path/to/your/image.png"

Controlling ubuntu suspend, hibernate and shutdown from the command line

gnome-power-cmd.sh suspend
gnome-power-cmd.sh hibernate
gnome-power-cmd.sh shutdown

The above are generic commands. For a specific laptop such as a Thinkpad T60p running linux, you can have a look at the /etc/acpi folder for commands like sleep.sh.

If your sleep fails, running the command manually will show you, on the terminal, where and how it's failing.

Launching screen saver from the command line

gnome-screensaver-command -l                                        

Some commands you may want to know.

To beautify gtk windows when not running gnome as a desktop:

$ gnome-settings-daemon &

To edit sound preferences:

$ gnome-sound-preferences &

To launch the power manager:

$ gnome-power-manager &

To launch the keyring daemon that stores your passwords:

$ gnome-keyring-daemon &

To turn on automounting (for your USB pen):

$ gnome-volume-manager &

How to mount a USB pen and camera

If you are in the default ubuntu gnome or kde desktop, you don't need this at all. From outside, edit your ~/.bashrc with the following:

alias pen='sudo mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/pen'
alias upen='sudo umount /mnt/pen'

... and be sure that the directory /mnt/pen exists.

The uid and gid options enable a specific user to read/write to/from the pen. To check your own uid and gid, use the id command in a shell.

When more than one USB device is to be mounted, it will get the next letter: sdb, sdc, and so on.

Running sound server in one computer, and mplayer in another


What this lets you do is to serve music or sound in general from a machine, and listen to it in another, such as your laptop.

In your laptop, where you want to hear music, open a shell and type:

$ esd -tcp -public

In the server, to play the sound of a movie:

$ ESPEAKERS= mplayer -ao esd -af volume=10 /path/to/file.avi

Replace the above movie file path by a music file to play that instead.

Thanks to Mark Longair for this tip!

Mount a samba share in fstab


For some reason beyond my understanding, gnome doesn't mount network shares, which means most applications cannot find the files from the share -because they don't have a proper file system path.

To fix the situation, edit your /etc/fstab file with sudo privileges, and add an entry like the following, replacing username by your local username, and shareusername and shareuserpassword by your remote share username and password:

//some/netshare /home/username/local/folder smbfs username=shareusername,password=sharepassword,uid=username,gid=username,file_mode=0777,dir_mode=0777  0 0

As an alternative, the same may be accomplished from bash:

$ sudo mount -t cifs -o username=shareusername,password=sharepassword,uid=username,gid=username,file_mode=0777,dir_mode=0777 //some/netshare /home/username/local/folder

How to control the fan speed for thinkpads using acpi


The following works fine for a Thinkpad T60p:

echo 0x2F 0x00 | sudo tee /proc/acpi/ibm/ecdump #(fan off)
echo 0x2F 0x02 | sudo tee /proc/acpi/ibm/ecdump #(low speed)
echo 0x2F 0x04 | sudo tee /proc/acpi/ibm/ecdump #(medium speed)
echo 0x2F 0x07 | sudo tee /proc/acpi/ibm/ecdump # (maximum speed)
echo 0x2F 0x80 | sudo tee /proc/acpi/ibm/ecdump #(automatic - default)
echo 0x2F 0x40 | sudo tee /proc/acpi/ibm/ecdump #(disengaged)

Just issue each command (without the comment!) on a shell, and be careful no to fry your laptop by using an improper setting.

Using XMMS2 from the command line

# xmms2 configuration
# for the USB headset:
xmms2 config alsa.device = hw:1,0
# for the volume
xmms2 volume right = 80
xmms2 volume left = 80
# to list the configuration options
xmms2 config_list | less
# to play a file
xmms2 play /path/to/music.mp3
xmms2 pause
xmms2 stop
xmms2 quit
# to list the current playlist
xmms2 list | less

Making an ssh tunnel for rsync or git


The tunneling technique allows you access via ssh, scp and rsync to a server that is invisible to the outside world, but which sits behind a visible server. Any number of tunnels may be concatenated together.

In your local machine, type the following in a shell and live it open:

$ ssh -N -f -L 3333:remote_server_name:22 loginname@visible.server.com
> password:   <---- for your visible server!

Then open a second shell in the local machine and type:

$ rsync -Cavz some/local/folder loginname@localhost:3333/path/to/invisible/server/folder
> password:   <---- for your INvisible server!

If your invisible server contains a git repository, you can pull from it like the following. In your local machine, type:

$ cd /my/repos
$ git pull ssh://loginname@visible.server.com:3333/path/to/invisible/repository

If you simply want to login to the invisible server, just type:

$ ssh -p 3333 loginame@visible.server.com

To copy a file from the invisible server to the local folder:

scp -C -P 3333 loginname@localhost:/path/to/invisible/server/file.txt .

Adding a group to a user

#To create the new group 'wg':
$ sudo addgroup wg

# To add user 'stephan' to the group 'wg':
$ sudo usermod -a -G wg stephan

Setting up a VNC connection for remote desktop


Install vncserver first and launch it at DISPLAY 1:

$ sudo apt-get install xvncviewer vncserver
$ vncserver :1

Now any machine may connect to the server:

$ vncviewer 

To connect to a machine that is behind a firewall with a pinhole on port 22 (SSH), with vncserver at port 1 as launched above, use:

$ vncviewer -via username@123.456.789.012 localhost:1

Checking hard drive properties


Tested on a Thinkpad T60p.

$ sudo hdparm -I /dev/sda

hdparm provides the ability to modify your hard drive settings. See man hdparm. USE WITH CARE.

To check the hard drive temperature, use:

$ sudo hddtemp /dev/sda

If you have more than one hard drive, try /dev/sdb, /dev/sdc etc.

Build a program from source painlessly


Suppose you want to install the very latest version of a program that already exists in the ubuntu repositories.

First you need to get all development files for the programs on which it depends on:

$ sudo apt-get build-dep <program-name>

Second just compile the program. If the ubuntu version is not much far apart, it will compile just fine.

How to print the header file information from a jpeg image, from python

First make sure the Python Imaging Library is installed:

$ sudo apt-get install python-imaging

Then open a shell and type:

$ python
>>> import Image, ExifTags
>>> im = Image.open("/path/to/image.jpg")
>>> for key, value in sorted(im._getexit().items()):
>>>     print key, ExifTags.TAGS.get(key), value

271 Make Canon
272 Model Canon PowerShot A85
274 Orientation 1
282 XResolution (180, 1)
283 YResolution (180, 1)
296 ResolutionUnit 2
306 DateTime 2005:08:14 10:24:05
531 YCbCrPositioning 1
33434 ExposureTime (1, 160)

How to send an email by telnet to an smtp server at port 25, the good old manual way

Below, a <CR> means 'enter' or 'carriage return'. Just type as is, including 'data' (which starts the body of the message) and 'quit'.

telnet smtp.somewhere.com 25
helo my_username.somewhere.com
mai from: <email-account>@username.somewhere.com
rcpt to: <email-account>@username.somewhere.com
The body of the message
goes here.

To reset a connection properly, use, at the end:


Talking to a web server via telnet at port 80

This is like navigating the internet manually.

$ telnet www.google.com 80
Connected to google.com.
Escape character is '^]'.

Then type or paste (with middle click), quickly before it closes, and follow it by two pushes to enter key:


Which responds with:

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=20f45537f4fc5e16:TM=1211048229:LM=1211048229:S=s7sijCPqZ_4rpsvC; expires=Mon, 17-May-2010 18:17:09 GMT; path=/; domain=.google.com
Date: Sat, 17 May 2008 18:17:09 GMT
Server: gws
Content-Length: 0

You can also try to fetch the whole page with (followed as well with 2 pushes to enter key):

GET / HTTP/1.1

Which prints the entire HTML code of the index page for google.com.

Have fun! With this simple command, one can write a web browser of sorts with very few lines of shell scripting or python or whatever.

Create a server to type text to:

This usage of nc lets you have some sort of chat with someone else who connect to your server via telnet.

For the server (where you can type text as well):

$ nc -l -p 3456

For the client (a.k.a. the other person connecting to you):

$ telnet xxx.xxx.xxx.xxx 3456

Where xxx.xxx... is the IP of the computer where the nc server was launched.

How to check the network security and open ports of your computer

Make sure nmap is installed, then:

 $ sudo nmap -sT -O -v

... which essentially runs a port scan on your local machine.

On each listed open port, now you can telnet to it and figure out what application daemon is behind it. For example, to test port 22:

$ telnet 22
Connected to localhost.localdomain.
Escape character is '^]'.
SSH-2.0-OpenSSH_4.3p2 Debian-5ubuntu1
telnet> quit

If you do the port scan on a remote machine, the responses of the daemon check with telnet may be obfuscated or faked (intentionally), without your knowledge. Garbage in, garbage out.

Fixing the disappearing ethernet network interface for Thinkpads

sudo modprobe -r e1000
sudo modprobe e1000
sudo idown eth0
sudo ifup eth0

How to adjust sound from the terminal, for speakers or headsets


Use alsamixer command. Each sound output is named a "channel". So to access the USB headset, use channel 1:

$ alsamixer -c 1

To change which channel is being used as default, launch:

$ gnome-sound-properties

... although most applications like xmms or skype will let you do so from within the application preferences dialog.

How to query a dictionary word from the command line

Make sure wordnet is installed. Then use:

$ wn <some-word> -over

... which gives an overview of the meaning(s) of the word, usually with examples of usage. Other options include antonyms, synonyms, etc. See man wn.

How to use xscreensaver from the command line


I have included in my .xinitrc script, which is read when launching X with startx. Something you won't be doing most likely if you use a graphical login for linux.

# launch screensaver ensuring it is not running
xscreensaver-command -exit
xscreensaver &

To lock at any time, just type:

$ xscreensaver-command -lock

How to disable the system bell even on a tty


Add a file ~/.inputrc and write in it:

set bell-style none

(Can also take parameter 'visible' to flash the screen instead of just remaining mute.)

Disable system bell

xset b off
xset b 0 0 0

Just put the above in any of your init scripts, such as ~/.bashrc .

Disabling once and forever the annoying system beep

Blacklist the kernel module pcspkr. Open the file /etc/modules.d/blacklist and add this entry:

# disable STUPID system beep speaker
blacklist pcspkr

Inspecting the database of installed debian packages with dpkg


To list packages and find out from which repository:

$ for p in `dpkg -l |grep ^ii | tr -s " " | cut -d " " -f 2` ; do echo $p ; \
      apt-cache show $p | grep ^Section: ; echo ; done | less

Listing all installed packages and sorting them by their installed size:

$ dpkg-query -W --showformat='${Installed-Size}\t${Package}\t${Status}\n' \
      | grep "ok installed" | sort -gr | less


$ dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | sort -rg \
      | grep "ok installed" | less

How to force file system integrity check on reboot


To force fsck on reboot:

$ sudo shutdown -F -r now


$ sudo touch /forcefsck
$ sudo reboot

How to list all computer hardware cards and devices


In linux:

lspci -v | less

In FreeBSD:

$ pciconf -l -v | less

How to adjust the gamma of your screen


Each graphics card usually has its own neat graphical application to do so (such as amdcccle for fglrx driver for ATI graphic cards.) But you can also use:

$ xgamma -rgamma 1.0 -ggamma 1.2 -bgamma 1.4

How to check battery and AC status from command line


In a Thinkpad T60p:

$ cat /proc/acpi/ac_adapter/AC/state 
state:                   on-line

$ cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          charged
present rate:            0 mW
remaining capacity:      70720 mWh
present voltage:         12492 mV

Other files under /proc/acpi are also useful to mine information about the state of the computer.

Installing and setting up apache with php and mysql

In ubuntu is really this simple:

$ sudo apt-get install apache php5 mysql-server-5.1 \
              php5-mysql libapache-mod-php5 php5-gd
$ sudo vim /etc/apache/httpd.conf
$ sudo vim /etc/php5/apache2/php.ini
$ sudo /etc/init.d/apache restart

Configuring a new graphics card and monitor / screen

So you installed a new graphics card and perhaps a new monitor, and on reboot, ubuntu doesn't seem to work at all. No problem:

  1. On boot, push ESC key when you see the Grub bootloader -a listing of ubuntu names.
  2. Push 'e' to edit, then 'e' again to edit the first entry.
  3. With the delete key, remove the last two words: quiet splash
  4. Now push enter. Ubuntu will boot and list all sort of things. Wait.
  5. You'll see that it tries 3 times to run the graphical login but it fails. It's ok. When it finishes, push enter a few times, until you see a login prompt. Enter user name and password.
  6. Now reconfigure graphics: type sudo dpgk-reconfigure xserver-xorg. Just follow instructions until done ('ok' to all questions will be fine.)
  7. When done you return to the prompt. Now type: sudo /etc/init.d/gdm reload && sudo /etc/init.d/gdm start and voilà, the graphical login will come back.
  8. Now go to System - preferences - Screen Resolution and adjust it for the new monitor. If the maximum resolution you know the monitor supports is not listed and you want it, then edit the file /etc/X11/xorg.conf - go to all entries listed as Section "Screen" and add to each the resolution the monitor supports, such as: "1680x1050", along with the other entries. Then logout, control+alt+F1 to go to the tty, sudo /etc/init.d/gdm stop && sudo /etc/init.d/gdm start, and then login into your desktop and back to System - Preferences - Screen Resolution to check/change it.

Enabling java plugin for Mozilla Firefox from an already installed sun java


In my case, I had java jdk1.6.0_10 installed from Fiji, which includes latest java 3d.

All you need to do is add a symbolic link. Assuming that you have fiji for 32-bit linux in your home directory:

$ sudo -l ~/fiji/java/linux/jdk1.6.0_10/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins/

Then restart firefox.

Enabling bluetooth in Ubuntu 8.10 Intrepid


In a Thinkpad T60p:

  1. Enable bluetooth first by switching the hardware switch on, on the front left side under your left hand wrist.
  2. Push fn+F5 to enable bluetooth on the running ubuntu. See how the bluetooth pilot lights up at the bottom of the screen frame.

To further inspect bluetooth state:

$ cat /proc/acpi/ibm/bluetooth
status:         enabled
commands:       enable, disable

Restoring wireless in Thinkpad T60p after sleep and resume


Can't get wireless lan up again after resuming unless:

sudo killall NetworkManager wpa_supplicant nm-system-settings nm-applet

sudo modprobe -r wlan_wep
sudo modprobe -r ath_pci
sudo modprobe -r ath_rate_sample
sudo modprobe -r wlan_scan_sta
sudo modprobe -r wlan

sudo modprobe ath_pci
sudo modprobe ath_rate_sample
sudo modprobe wlan_wep
sudo modprobe wlan
sudo modprobe wlan_scan_sta

sudo NetworkManager
nm-applet &

Just save it into a convinient bash script.

Inspecting properties of an open Xorg window in the desktop


Run the following in a terminal and then click on a window:

$ xprop

You may also see xwininfo.

Fixing Master Boot Record (MBR)


If you manage to missinstall the master boot record MBR, you can reinstall it from a running system with:

$ sudo grub-install /dev/sda

Capturing HTTP requests

$ sudo tcpdump -i eth0 -A -s0 | grep -Eo "(GET|POST).*$"

... then open/reload any web page.

Recording X server, or recording desktop acitivity for a tutorial

Recording X server with xvidcap doesn't yield enough frames per second (fps), so instead Mark Longair recommends:

05:37 and by far the most reliable for me was ffmpeg
05:38 (recording raw video so no CPU was used up on encoding at the time)
05:41 i think i used:
05:41 ffmpeg -vcodec rawvideo -f x11grab -s 1024x768 -r 10 -i :0.0 foo.yuv
05:42 (for 10 fps)
05:42 and then afterwards transcoding that gigantic file with something like:
05:42 ffmpeg -pix_fmt rgb565 -s 1024x768 -r 10 -vcodec mpeg4 -mbd rd 
              -flags +4mv+trell+aic -cmp 2 -subcmp 2 -g 300 -pass 1/2 -i 
              foo.yuv -r 10 foo.avi
05:43 (rgb565 since i changed to 16 bit colour depth to reduce the size of the raw video

Last updated: 2012-05-08 11:10 Zurich time. Copyright Albert Cardona.