Monday, 25 August 2008

Manipulating files and folders

Apologies for the delay since my last post - as I don't have access to the Internet during the week at present and my parent's Internet connection has been playing up, it's been hard to get any blogging done! Hopefully that will change soon!
Anyway, manipulating files and folders is something that you need to know about, seeing that Linux applies the Unix philosophy of "everything is a file". So I'll walk you through some basic commands.
First up is mkdir. This command makes a new folder. So, if you're in your /home directory and you enter the following:
mkdir Work

You'll create a new directory called Work. Never forget that Linux, unlike Windows, is case sensitive. Also, if you want to create a new directory anywhere other than in your own /home directory, you'll need to use sudo.
To remove an empty directory, you can use rmdir, as in this example:
rmdir Work

Now, to remove a file, you use the rm command, as in this example where we're deleting the document Example.html:
rm Example.html

Like most commands in Linux, rm has a number of options you can specify. A word of warning: watch out for the command rm -rf. The r option means remove things recursively (so you can remove a directory AND everything inside it), while the f option forces it, even if it gives a warning. You can specify the folder you want to delete with its path, so NEVER run the following command (unless you actually want to destroy your system!):
sudo rm -rf /

This means "delete the whole filesystem recursively, ignoring all warnings, with root access", essentially meaning delete everything!. I've tried this on VirtualBox installs of Ubuntu and it will destroy everything on your system! That said, the command rm -rf can be quite handy for deleting a folder and it's contents, but be VERY careful with it!
To copy a file, use the cp command, with the source followed by the destination, as in this example:
cp Example.html /media/USB

You can change the name of the destination by specifying the file name as well, like this:
cp Example.html /media/USB/Example2.html

Moving a file is similar to copying it, with similar syntax:
mv Example.html /media/USB

And again you can change the name, in the same way as with cp. Or you can use it to rename a file without moving it, like this:
mv Example.html Example2.html

Now, moving files and folders is all very well, but how can you show them? Simple, use the ls command:
ls

To show hidden files and folders as well, use this:
ls -A

As usual, if you want to know more about these commands, refer to the man pages for more specific guidelines. Hopefully this has given you enough to get started. I recommend spending a little time becoming comfortable with these commands, they'll give you a sound grasp of the fundamentals of using the command line.

Saturday, 26 July 2008

Navigating folders from the command line

If you've followed the posts on this blog for a while, you should be reasonably comfortable using the command line to install software, edit configuration files and so on. You should also be aware of the layout of the Linux filesystem. However, you may not be aware of how to navigate it without using a graphical file manager such as Nautilus or Konqueror. So in this post I'm going to go through basic commands for navigating from the command line.

First of all is the cd command. This is short for "change directory". The default location for you to start is in your home directory, and entering the following:
cd

will take you to your home directory. You can also use the ~ character (known as a tilde) as shorthand for your home directory, which is useful if referring to your home directory from elsewhere. So, entering the following:
cd ~

will give the same results as the previous command.

You can also navigate up one directory as follows:
cd ..

And can go back to the previous directory using this command:
cd -

These commands can be used as part of longer paths. For instance, say you are currently in /var/www but want to go to a folder called Music in your home folder. You can go there with this command:
cd /home/username/Music

Or you can use this:
cd ~/Music

Now, say you want to go from there to another folder in your home directory called Pictures. You can enter this:
cd ../Pictures

Then, to head back to the Music folder, you can enter the following:
cd -

And to head to the root of the filesystem, just enter the following:
cd /

Now, how can you see where you are? Easy, just enter the pwd command (short for Print Working Directory). Here I'm in the Desktop directory:
/home/matthew/Desktop

Got that? I recommend you spend a little time getting comfortable with these commands as they are the first building blocks in becoming proficient at the command line. Next time I'll go into creating and deleting files and folders.

Sunday, 20 July 2008

Recreating my Ubuntu desktop

I've been asked how to recreate the desktop I showed in the previous post in Ubuntu. For those who haven't seen it, here it is:


OK, first of all there's a number of applications you need (I'm assuming you're working from a fresh install). So run the following command:
sudo apt-get install avant-window-navigator awn-manager compizconfig-settings-manager emerald gnome-do gnome-do-plugins
Strictly speaking, Gnome Do isn't required as it doesn't contribute to the appearance, but it's a very handy application launcher.

Once these are installed, you'll need to remove the bottom panel. Move any applets you want to keep up to the top panel, then right-click on the bottom panel and select Remove This Panel. To set Avant Window Navigator to run when you start up, go to System>Preferences>Sessions and select Add. Then enter Avant Window Navigator as the name, and /usr/bin/avant-window-navigator as the command. You can put anything you like for the description (I put "Mac OS X-style dock bar").

Now to grab the packages you need:
  1. Genesis Emerald Theme
  2. Blue-Joy GTK Theme
  3. Oxygen Refit 2 Icon Theme
  4. Peace Wallpaper
Now open System>Preferences>Appearance. From the Theme tab, click on Install. You'll be able to browse your filesystem for the theme packages you just downloaded. Use this method to install the Blue-Joy GTK theme and the Oxygen Refit 2 icon theme. For the background, go to the Background tab, click on Add, and select it using the file browser. You might want to copy it to your/usr/share/backgrounds so all users can have it - this can be done with the following command:
sudo cp (insert name of image here) /usr/share/backgrounds

Finally, to install the Emerald theme. Go to System>Preferences>Emerald Theme Manager. Click on Import, select the theme package, and click on Open. You should then be able to select the theme package from the list of those installed.

However, it won't have any immediate effect as Emerald isn't running. To start it up, enter the following command at the terminal:
emerald --replace

To make Emerald always be the default window decorator, open CompizConfig Settings Manager and look for Window Decorator under Effects. Check the box, then click on the icon to adjust the settings. Replace whatever is in the Command box with emerald --replace.

If you now log out, restart your X window server using the Options menu from the login page, then log back in, Emerald and AWN should be running straight away. You can then add whatever launchers you want, but by default AWN only has the launcher applet. If you want to add Ubuntu Tweak so you can add more applets to AWN, please refer to my previous post.

If you're interested in recreating the dock bar I've got, here it is from left to right:
  1. File Browser applet
  2. Firefox launcher
  3. Exaile music player launcher
  4. VLC media player launcher
  5. GIMP launcher
  6. Evolution launcher
  7. Pidgin launcher
  8. Jokosher audio editor launcher
  9. Kino launcher
  10. F-Spot launcher
  11. Skype launcher
  12. Last.fm launcher (not the Last.fm applet, I couldn't get that to work)
  13. XChat IRC client launcher
  14. Time Vault launcher
  15. Ubuntu Tweak launcher
  16. Gnome Terminal launcher
  17. Showdesktop applet
  18. Stacks Trasher applet
I personally really like this desktop. I'm normally more of a KDE guy (I have a separate Kubuntu install on another computer, while this computer is dual-booting Vista and Ubuntu), but I really enjoy working in this kind of environment. I've added two more virtual desktops so as to get the cube effect, and the whole thing looks amazing.

One problem with using this theme is that a lot of things are black that aren't normally (such as the paper in OpenOffice!) and I haven't yet found a way round this, so this might be a problem. I'm hoping the theme's author will be able to resolve this.

Saturday, 19 July 2008

Using Ubuntu Tweak to get third-party apps

The likes of Compiz and Avant Window Navigator are great for improving the appearance and usability of your Ubuntu desktop, but out of the box many of them don't include the latest and greatest features. For instance, Avant Window Navigator is available from the Ubuntu repositories in Hardy, but there's no applets available from there other than the launcher applet. This is a shame as there are a lot of applets which improve the functionality of AWN no end. The same applies for Compiz - how can you get new new plugins such as Cube Deformation (allowing you to change the cube to a cylinder or sphere)?

Now, one way is to add the respective PPA (Personal Package Archive) on Launchpad to your /etc/apt/sources.list. But there's an easier way - Ubuntu Tweak. This incredibly useful application allows you to quickly and easily add these third party repositories using a graphical interface. Normally I'm a strong advocate of the command line in this context, but we've gone through adding additional repositories in the past, and in this case I feel Ubuntu Tweak is the easier way to do it.

To get started, first download and install the package as usual. Run it as normal and you will come to a screen like this:


Select Applications, then Third Party Software Sources. This will take you to a list of the software that you can use Ubuntu Tweak to keep up to date with. You'll need to click on Unlock and enter your password before you can add anything (this is because Ubuntu Tweak needs root access to add the new repositories).
Now you can add the repositories for whatever apps you wish to keep up to date with, whether that's the latest versions of Google Gadgets, AWN, Compiz, Wine or whatever takes your fancy. Once you've selected what you want, click Refresh. The new repositories will be added and Update Manager will open - you'll need to enter your password again and an apt-get update will run automatically.
Now that you have the new new repositories added, you can get the newest versions of the apps you've chosen just by running the following:
sudo apt-get update
sudo apt-get upgrade

However, there are a few things that aren't included by default, and additional applets for AWN are one of them. To add these, once you've added the AWN repository from Ubuntu Tweak, just run the following command:
sudo apt-get install awn-applets-c-core awn-applets-c-extras awn-applets-python-core awn-applets-python-extras

This will install the applets available from the repository. You'll no doubt find that Avant Window Navigator becomes enormously more powerful once you add these additional applets. You can do a lot with it once you get used to it.

Ubuntu Tweak can be incredibly handy for non-technical users. It acts as a great one-stop control panel, and allows you to get some of the newest and most impressive goodies available for Linux. But unlike Automatix, it's safe to use and won't destabilise your system. For demonstration purposes, here's the Sphere effect. It's under Cube Reflection and Deformation in CompizConfig Settings Manager.


Pretty impressive, huh? Hope you have fun with Ubuntu Tweak!

Wednesday, 9 July 2008

Backing up your system with Remastersys

I've previously mentioned how to set up /home on a separate partition to help ensure that your data is safe if anything goes wrong with your Ubuntu install. However, we all like to add a few extra applications and other things, and if anything goes wrong, it will take you a long time to reinstall these. How can you make this easier?
Simple, use Remastersys. This incredibly handy utility allows you to create your own customised install CD based on your Ubuntu or Linux Mint installation. It's actually used to create a few Ubuntu derivatives, and you can quite easily use it for this purpose yourself if you so wish, as you can use it to create a distributable copy. I now have a DVD based on my Kubuntu install so I can easily reinstall it if anything goes wrong, and it includes all the multimedia codecs so everything works out of the box. And it's extremely easy to use.
So, how do you install it? It's not in the Ubuntu repositories, but there is a Remastersys repository which you can add. Just enter the following:
sudo vim /etc/apt/sources.list

As always, you can use nano or another editor if you prefer. Now add the following lines:
# Remastersys
deb http://www.remastersys.klikit-linux.com/repository remastersys/

Now run the following commands to install it:
sudo apt-get update
sudo apt-get install remastersys

Before you run it, you may want to change some of the settings. These are in a text file at /etc/remastersys.conf. This file is very straightforward to use, and everything is well signposted - you can easily change the name of the customised CD by editing this file.
Now, when you run Remastersys, it will create an ISO image based on your current install, so for instance if you're running Ubuntu but have added the Kubuntu desktop, it will be on the CD as well.
Before you run it, close down every other application you are running as they can affect the build. There are two ways you can run it. To back up everything, including user's directories, run the following:
sudo remastersys backup

If you're planning to distribute copies of this to other people, for instance if you are using Remastersys to create your own distro, you won't want to run this. Instead, run this command to create a distributable version which you can give to others:
sudo remastersys dist

The process can take a while, especially if you have a lot of applications installed. Be aware that ISO images of over 2GB can have trouble booting, however don't worry if your system takes up more space than that as it's compressed significantly when the ISO image is built (the standard Ubuntu install takes up around 2GB when installed, but around 700MB as an ISO). Please also note that an image larger than 700MB will need to be burned to a DVD.
Once the process has finished, if you go to the /home directory, you'll notice an extra user directory has been added - Remastersys. Go into this directory, and there's another Remastersys folder inside that. Inside you'll find your new ISO image, which you can move to your own home directory, along with an m5d checksum.
Now that's done, you can clear up the build directory. This is easy, just enter the following:
sudo remastersys clean

Make sure you've moved the ISO to your own directory before you do this. Now you can use whichever CD-burning tool you prefer to burn the disc to a CD or DVD, and you now have your own customised Ubuntu!
There are endless uses for this. I've been experimenting with creating my own distribution using this method - so far it's pretty poor, but it's educational. With a distributable copy of your install and with your /home directory on a separate partition, it's easy to restore your system in case anything goes wrong. You can create a copy of your install and run it in VirtualBox so that you can use that as a test bed for any changes you might want to make. And it can be handy to have with you as it means you can boot any computer into your own familiar desktop environment, with your own favourite applications, without having to install a thing. I urge you to try it!

Sunday, 8 June 2008

Closing applications that have hung - part 2

In my previous post, there were some things I missed out, which I'll now fill you in on. First of all, if something has hung, it can be a pain to try and launch a terminal just to close something down, but you don't need to. Just press Alt+F2 in Ubuntu to get the Run dialog and enter xkill there.

But what about if the entire screen has hung and it's too slow to do anything? Well, there's several options here. You can press Ctrl+Alt+Backspace to restart your X window server, but that's overkill. A better idea is to press Ctrl+Alt+F2 to take you to a virtual terminal. You can log in by entering your username, then you'll be prompted for your password. Once you've logged in, enter the following command:
top

This displays a list of the running applications. It includes details of how much memory and CPU each is using. Look for the application you want to stop, and note the PID (process ID) number. Then press Q to exit top.

Now you know this number, it's easy to kill the process from the command line. If this number was 1234 for the program you wanted to stop, you'd enter the following:
kill 1234

Easy! Now press Ctrl+Alt+F7 and you'll be back at your desktop as usual, minus the hung application.

Mounting partitions and other devices from the command line

Many Linux users dual-boot with another operating system, and it can be inconvenient if you can't get access to the files you have in that partition. For instance, if you are dual booting Windows XP and Ubuntu, perhaps you'd like to be able to play some music from your hard drive in Rhythmbox, but you can't get at it. Ubuntu is pretty good at mounting new filesystems automatically, but it's not perfect, so it pays to take the time to learn how to do it yourself. Don't worry, it's not that hard!

If it's an external device such as a flash drive that you want to mount, then connect this. Then run the following command in the terminal:
sudo fdisk -l

This will display all the filesystems that your system can detect, whether they are mounted or not. For example, here's mine on my Kubuntu laptop:
matthew@matthew-laptop:~$ sudo fdisk -l

Disk /dev/sda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008acac

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2918 23438803+ 83 Linux
/dev/sda2 2919 3042 996030 82 Linux swap / Solaris
/dev/sda3 3043 4864 14635215 83 Linux
matthew@matthew-laptop:~$

Don't worry if this looks confusing. All you need to look for is the Device and System columns. The system column shows the filesystem used - this can be handy as different operating systems use different filesystems, so it would be easy to recognise a Windows-formatted partition - it would show as something like FAT or NTFS. The device column shows the device each partition is on - /dev/sda is the hard drive. /dev/sda1 is one partition, /dev/sda2 is another and so on. A different device would show up as something else, such as /dev/sdb, and its partitions might show as /dev/sdb1 and so on.
So you should have no problem identifying which partition it is you want to mount. Once you know this, we can get started. If you remember from an earlier lesson, Linux will happily slot a new partition in anywhere you tell it to, you just have to say where. It's best to put it in the /media directory if it's something temporary like a flash drive, whereas /mnt is better for more permanent things like your Windows partition. You'll need to create a directory in which to mount it to make it easier to manage, something like this:
sudo mkdir /mnt/windows

Then, once that's done, you can issue the command to mount the partition there. If the Windows partition was /dev/sda3, you could mount it in /mnt/windows as follows:
sudo mount /dev/sda3 /mnt/windows

Once this is done, you should be able to browse the newly added partition or device with ease. If you want to remove it manually, issue this command:
sudo umount /dev/sda3

If you'd like to mount something automatically when you boot up, such as your Windows partition, you can install the pysdm package. Then open the new Storage Device Manager, which will enable you to easily set up partitions to mount at boot, and specify where you want them.