Tech stuff and info dump

How to list partitions and basic partition information: linux

May 31st, 2010

To find out basic information about partitions, open a terminal window (Applications -> Accessories -> Terminal in Ubuntu 10.04 and others) and type

fdisk -l

at the command line.

(If nothing happens, try typing

sudo fdisk -l

at the command line and entering your password when prompted.)

Something like this should be displayed:

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x66666666

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2613 20988891 c W95 FAT32 (LBA)
/dev/sda2 2614 17532 119830471+ f W95 Ext’d (LBA)
/dev/sda3 17532 19458 15471448 12 Compaq diagnostics
/dev/sda5 13566 17532 31856640 7 HPFS/NTFS
/dev/sda6 2614 13194 84991819+ 83 Linux
/dev/sda7 13195 13565 2980026 82 Linux swap / Solaris

Here, /dev/sda6 is my linux partition.

In Ubuntu 10.04, you can navigate to System -> Administration -> Disk Utility to get a big graphical display of this information (and more).


Filed under: Command line,linux
May 31st, 2010 11:09:40

How to tell how much disk space is left: linux

May 31st, 2010

Open a terminal (Applications -> Accessories -> Terminal in Ubuntu 10.04 and others) and type

df

at the command line.

Something like this will be displayed:

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda6 83657080 25098664 54308828 32% /
none 504088 296 503792 1% /dev
none 508500 372 508128 1% /dev/shm
none 508500 96 508404 1% /var/run
none 508500 0 508500 0% /var/lock
none 508500 0 508500 0% /lib/init/rw

The number listed on the top line (/dev/sda6) under ‘Available’ is the amount of space left on my linux partition.

For more human-readable numbers, try:

df -h

which will display something like this:

Filesystem Size Used Avail Use% Mounted on
/dev/sda6 80G 24G 52G 32% /
none 493M 296K 492M 1% /dev
none 497M 372K 497M 1% /dev/shm
none 497M 96K 497M 1% /var/run
none 497M 0 497M 0% /var/lock
none 497M 0 497M 0% /lib/init/rw

The df command won’t show space available on unmounted drives.

If you want to see basic information about the partitions on a machine, see this post.


Filed under: Command line,linux
May 31st, 2010 10:58:03

python: generate a list of uppercase or lowercase letters in the alphabet

May 30th, 2010

To create a list of lower-case letters in the alphabet in python:

map(chr, range(97, 123))

To create a list of upper-case letters in the alphabet in python:

map(chr, range(65, 91))

Examples:

>>> map(chr, range(65, 91))
[‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’]

>>> a=map(chr, range(97, 123))
>>> a
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’]


Filed under: python,script
May 30th, 2010 16:59:09

Ubuntu 10.04: change focus when mouse moves to different window

May 30th, 2010

I like the focus to change when I move my mouse so that I can type in one window whilst having another window on top.

To make this happen in Ubuntu 10.04, go to System -> Preferences -> Windows and click the tickbox next to the statement, “Select windows when the mouse moves over them”.


Filed under: desktop,GNOME,Ubuntu 10.04
May 30th, 2010 16:51:40

Save python history across sessions (linux, Ubuntu)

May 30th, 2010

To get python to save history across sessions you put the file .pystartup in your home directory and you add the line

Open a terminal and go to your home directory.

(In Ubuntu 10.04 and other versions, navigate to Applications -> Accessories -> Terminal to bring up a terminal window. You should already be in your home directory.)

Add the line

export PYTHONSTARTUP=/home/name_of_home_directory/.pystartup

to the .bashrc file, replacing name_of_home_directory with the name of your home directory.

(In Ubuntu 10.04 and other versions, you can open this file by typing

gedit .bashrc

at the command line. This will bring up a simple editor. Just add the line given above to the bottom of the file, save the file and close the gedit window.

The name of your home directory is the string that appears before the @ sign in your command line prompt, assuming you haven’t done anything to change this. For example, your prompt might look like this:

name_of_home_directory@mycomputer:~$

You can also find it by going to Places->Home Folder. The window that pops up will have the text

name_of_home_directory – File Browser

at the top.)

That should do it!

Thanks to archduke.


Filed under: Customisation,python
Tags:
May 30th, 2010 15:00:13

OpenOffice Calc: How to turn off auto-correct for (C) (R) and -> <- arrows

May 26th, 2010

Recently, I wanted to include a string like this:

Latin (C)

in an OpenOffice spreadsheet.

Unfortunately, every time I entered ‘Latin (C)’, the ‘(C)’ would get changed to a copyright symbol. Ctrl-z would erase the entire entry, rather than revert the copyright symbol to the string I typed in the first place.

To turn off this behaviour, I went to ‘Tools -> Autocorrect…’ and selected the ‘Replace’ tab. This gives a big list of all the auto-corrections OpenOffice will make.

I clicked on each item that I didn’t want OpenOffice to ‘fix’ for me and clicked ‘Delete’ to remove the entry.

Alternatively, one can go to ‘Tools -> Autocorrect…’, select the ‘Options’ tab and uncheck the box next to ‘Use replacement table’. Doing this should prevent OpenOffice from making any of the changes listed in the ‘Replace’ list. (It is worth having a look through the other tickboxes here as there were several other things I wanted to untick, like fractionifying fractions and making URLs into links.

This worked on OpenOffice Calc 2.4.1 running on Ubuntu 8.04 (Hardy Heron).


Filed under: Customisation,Fixes,OpenOffice
May 26th, 2010 16:04:55

Ubuntu 10.04: Get rid of the whizzy desktop-switching slide animation and other graphical effects

May 18th, 2010

I prefer a simple desktop environment free from whizzy graphical effects. In particular, I didn’t like the whooshing between desktops. I think of my desktops as discrete spaces and didn’t want them to appear connected in any way. In particular, I didn’t want to be able to move a window halfway off the left-hand side of the screen and then find it on the desktop to the next desktop over. How disorienting!

To disable the default

Navigate to System -> Preferences -> Appearance
Click on the ‘Visual Effects’ tab
Choose the ‘None’ option
Click ‘Close’

This freed me from all the unwanted effects.

(To disable only the desktop whooshing and not other graphical effects, perhaps it would be worth exploring ubuntu-tweak. After Ubuntu Tweak is installed, it can be accessed via Applications -> System Tools. I suspect playing around with “Compiz Settings” under the ‘Desktop’ heading could help. I may try this if I find a nice feature missing now that I’ve turned off visual effects, but for now, I’m happy.)


Filed under: Customisation,Ubuntu 10.04
May 18th, 2010 17:49:43

Ubuntu 10.04 printing fix: getting rid of the light yellow/cream background when there should be a white background

May 18th, 2010

Update 4 June 2010: the latest round of updates took care of the problem. If you’ve not yet updated, try System -> Administration -> Update Manager. Thanks for the heads-up, Reinout van Rees!

Ever since installing 10.04, I’ve found that I occasionally get rogue light yellow/cream-coloured backgrounds when I print images with a white background. This hasn’t happened with my machines running 8.04 or 9.04.

I’ve had this problem printing from OpenOffice and from Firefox; in both cases, I was printing a .jpg with a white background. I verified with xmag that there was no colour in the background that I was trying to print.

There is a Debian bug report and an Ubuntu launchpad bug report with more information and a temporary work around.

Open a terminal window (Applications -> Accessories -> Terminal) and enter the following:

cd /usr/lib/cups/filter/

to move to the /usr/lib/cups/filter directory.

Optional: make a back-up of the file that needs to be edited by typing

sudo cp pstopdf pstopdf.backup

and entering your log-in password if prompted.

Open the file pstopdf in your favourite text editor. This can be done using gedit by typing

sudo gedit pstopdf

and entering your log-in password if prompted.

There should be a line that looks like this:

PS2PDF_OPTIONS=”$PS2PS_OPTIONS -dColorImageFilter=/FlateEncode \
-dPDFSETTINGS=/printer -dUseCIEColor”

Delete -dUseCIEColor so that the line appears like this:

PS2PDF_OPTIONS=”$PS2PS_OPTIONS -dColorImageFilter=/FlateEncode \
-dPDFSETTINGS=/printer”

Save the file.

This worked for me with a Lexmark C544 printer. However, I don’t know what is causing the problem and I don’t know anything about what these options do. Fingers crossed, a ‘proper’ solution will be on its way….

Thank you, vbi, for the work-around!


Filed under: Fixes,printing
May 18th, 2010 13:14:07

Changing MySQL root password (using phpMyAdmin, Ubuntu linux)

May 13th, 2010

If you have phpMyAdmin installed, it can be used to change the MySQL root password. (If you don’t have phpMyAdmin installed, there are installation instructions in this post.)

  1. Log in to phpMyAdmin. (If you have phpMyAdmin set up as described in this post, log in to phpMyAdmin by opening a web browser like Firefox and entering http://localhost/phpmyadmin/ as the URL.)
  2. Click on the ‘Privileges’ tab to view a list of all Users.
  3. Click the little pencil icon in the rightmost column of each ‘root’ account.
  4. Enter a password in appropriate field of the newly-loaded page.

Filed under: mysql,php,phpmyadmin
May 13th, 2010 13:11:13

Ubuntu 10.04 (Lucid Lynx): simple, step-by-step lamp server installation (linux, apache, mysql, php)

May 13th, 2010

Well, today’s the day for installing a lamp server on my 10.04 machine! Wireless is working just well enough that I’ve not given up and gone running back to 9.04, although there are still some mysteries to figure out where that’s concerned.

It’s worth noting that I’m setting up my server for personal use. I want something that will let me test out webpages that will hosted by other people’s servers. (If you’re setting up an internet-facing server, these instructions will get you started, but more work is needed to keep the server safe from the wild world of the internet. If I come across a good tutorial on such things, I’ll post it.)

Downloading Necessary Packages

Synaptic Package Manager can be opened by going here:

System -> Administration -> Synaptic Package Manager

and entering one’s password.

I used Synaptic Package Manager to download the following packages:

  • php5 (this installs apache2-mpm-prefork, etc.)
  • mysql-server-5.1 (this installs the client and core as well)
  • Optional: phpMyAdmin (a nice GUI for managing MySQL tables)
  • Optional: php5-cli (only needed if you want to run PHP from the command line)

The packages can be found by clicking the Search icon and typing in the package names. When a package name is selected, Synaptic Package Manager kindly prompts one to install all other files required. Once you have chosen all the packages needed, click ‘Apply’ (underneath the green check mark) at the top of the Synaptic Package Manager window.

File Installation

For the most part, Synaptic Package Manager will take care of all the installation. There are a couple things that might need to be done manually, however.

Configuring phpMyAdmin

If you have chosen to install phpMyAdmin, you may get a pop-up window called ‘Configuring phpmyadmin’ with the text “Web server to reconfigure automatically:” and a choice of servers. This is just asking which server you want to be able to run phpMyAdmin. I was given the choice of apache2 and lighttpd. I ticked apache2 and clicked the ‘Forward’ button.

Configuring MySQL

The mysql installation also requires some information. A pop-up window called ‘Configuring mysql-server-5.’ should pop up with the text ‘New password for the MySQL “root” user:’ and a text box.

Make up a password for the root user and enter it into this box. (Write it down – you’ll need it later!) Click ‘Forward’. You’ll be asked to re-enter the password. Do so, and click ‘Forward’ again.

Database for phpMyAdmin

If you’ve chosen to install phpMyAdmin, you’ll get another ‘Configuring phpmyadmin’ pop-up with the text ‘Configure database for phpmyadmin with dbconfig-common?’ and a tickbox. I left this ticked; clicking ‘Help’ explains under what circumstances one wouldn’t want this to happen. Once the selection is made, click ‘Forward’ to continue.

If the box was ticked, you are then prompted for “Password of the database’s administrative user:” and given another text box. Use the MySQL root password that you just made up.

After this, the installation should complete itself without any more human help.

Restarting the Apache server

Before anything can be done, the Apache server will need to be restarted.

Open a terminal (Applications -> Accessories -> Terminal) and, at the command line, type:

sudo apache2ctl restart

The first time I did this, I received this warning:

apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

This went away when I did this:

Letting Apache know about localhost

Open a terminal (Applications -> Accessories -> Terminal) and, at the command line, type:

sudo gedit /etc/apache2/apache2.conf

The sudo command gives you root-like powers (needed here to edit this particular file), gedit opens the notepad-like application, and /etc/apache2/apache2.conf is the name of the file being edited.

(If prompted for a password, use the password that is used to log in to Ubuntu.)

This should open a notepad-like window with a lot of stuff.

I added

ServerName localhost

as a separate line at the end of the file and saved the document (File -> Save in gedit).

After saving, restart Apache again by typing

sudo apache2ctl restart

at the command line.

Testing to make sure PHP works

Open a terminal window by going to

Applications -> Accessories -> Terminal

Type this (pressing enter when finished) at the command line:

cd /var/www/

This takes you to the /var/www folder. Then type:

sudo gedit

and press enter. You’ll be prompted for your system password (the one used to log in to Ubuntu). (The ‘gedit’ opens a notepad application; the ‘sudo’ is necessary because if gives you root-like powers which are needed to save a file in the /var/www folder.)

In the notepad application that should have popped up, type the following:

# test.php
<?
phpinfo();
?>

Then go to File -> Save As and enter test.php as the name of the file.

Open a browser (like, say, Firefox at Applications -> Internet -> Firefox Web Browser) and type

http://localhost/test.php

and you should get a page come up with all sorts of useful and interesting information about your Apache server! It works!

(If you get a page that just says “# test.php” then Apache doesn’t know about localhost. Try editing /etc/apache2/apache2.conf and restarting the Apache server as described above.)

Setting up phpMyAdmin

If you’ve opted for phpMyAdmin, there is one quick little thing to do to make it work.

Open a terminal window (Applications -> Accessories -> Terminal) and type:

sudo gedit /etc/apache2/apache2.conf

at the command line prompt. If prompted for a password, use the password for logging in to Ubuntu.

Add this line to the file that has been opened in the notepad-like window:

Include /etc/phpmyadmin/apache.conf

Make sure this is on a line of its own. Save the file (File -> Save), close the gedit window and restart Apache by typing:

sudo apache2ctl restart

at the command line prompt.

Check to make sure phpMyAdmin works

Open your favourite web browser (say, Firefox) and navigate to:

http://localhost/phpmyadmin/

This should bring up a login screen. You can log in to phpMyAdmin by using ‘root’ as the username and the mysql root password set during installation.

The mysql root password can be changed in phpMyAdmin by going to the privilege page and clicking the pencil icon next to each root account. Enter a password in appropriate field of the newly-loaded page.

Once logged in, you can use phpMyAdmin to manage your MySQL databases.

Where Important Things Are

Here’s where to find useful stuff.

The Apache configuration file is located at:

/etc/apache2/apache2.conf

The default web folder is here:

/var/www

Apache error logs are here:

h1

If anything goes horribly wrong, reading these can often be very helpful. (Even if what’s written in the file makes no sense, it’s often quite easy to pop the error message or warning into Google. Very often, there’s someone talking about the problem using real words in the first page of hits.)

Apache access logs live here:

/var/log/apache2/access.log

NB: Both etc and var can be found two levels ‘up’ from the home folder.


Filed under: apache,lamp server,mysql,php,Ubuntu 10.04
May 13th, 2010 12:54:28