Using ll as an alias for ls -l in Ubuntu

Redhat, and possibly other, distros have the ll shell shortcut defined – it’s a shortcut to save you typing ls -l all the time. Once you start using it you really miss is badly when it’s not available. Ubuntu doesn’t have it setup as default.

But that’s easy to fix by editing your .bashrc file. The .bashrc file is in your home directory, open it in an editor, uncomment the following line and save:

#alias ll=’ls -l’

Note that files beginning with a dot are hidden files and you won’t be able to see them using Nautilus or any other GUI file browser by default. In Nautilus, navigate to your home folder and right-click in it and select show hidden files.

Running a linux application (process) in the background

Say, for example, you have an application called DoStuff. For sake of argument lets say that this app scans a directory and searches for files called “steve.txt”. Because you have a large directory structure, this can take a number of minutes to complete.

You can run this from a console by simply typing its name:

steve@steve-desktop:~$ DoStuff

By doing this you will have to wait until the application has finished before you have control of this console again.

If you want to run this application in the background then you can simply add a “&” to the end of the command:

steve@steve-desktop:~$ DoStuff &

DoStuff now runs in a background process and you have not blocked your console. Of course, you could always open multiple console windows but that quickly clutters the screen up if you have too many.

You will notice that once your background process has finished running DoStuff it will print a status message to the console it was run from. Something along the lines of:

[1]+  Exit 1                  DoStuff

This is a notification that the process has finished – you will see an error message if DoStuff terminated with an error

Linux recursive grep

To recursively grep through directories you can use the find command to select a filenames in a directory tree and then grep to find a string within each file.

Here’s the command to find the string facebook in all javascript (*.js) files in the current directory and any sub-directories:

find . -name ‘*.js’ -exec grep ‘facebook’ -Hn ‘{}’ \;

Breaking that command down:

The first find parameter is the . that instructs it to start in the current directory. The -name parameter is followed by a filename wildcard to match, *.js in this case. Next parameter is the -exec, this is an instruction that find will execute for each file it finds – we are using grep. The grep ‘facebook’ -Hn is the grep command and its parameters – it tells grep to look for the string facebook and -Hn tells it to output the filename and line number of all matched files. Finally, the ‘{}’ \; are find parameters that instruct it to call grep for each file.

We can recursively grep for all files by omitting the -name parameter:

find . -exec grep ‘facebook’ -Hn ‘{}’ \;

We can look in another directory by changing the . for a directory name:

find /home/steve -exec grep ‘facebook’ -Hn ‘{}’ \;

Because this is a bit of a pain in the ass to remember I usually create a bash script called rgrep.sh or something like that and just call it from that.

Ubuntu problem: you are not privileged to mount volume

I’ve recently been getting the “you are not privileged to mount volume” message when I’ve been trying to access either my USB stick or external hard drive from Ubuntu Hardy Heron.

The first thing that might cause this is that you really don’t have privileges – yeah, I know, shocking. Try going to System->Administration->Users And Groups. Wait for the User Settings dialog to pop up and then pick the user having the trouble (probably your own). Once you have selected the user click Properties. Now click the User Properties tab at the top and look at the top checkbox on here called Access external storage devices automatically. Normally this will be checked by default, if it is not: Go back to the front page of the User Settings dialog and select your user again and this time select Unlock – you can now edit the user’s settings.

That could really do with some screenshots, couldn’t it?

Now, if your user does have Access external storage devices automatically selected then it is probable that the OS simply cannot mount the drive and is giving you a slightly confusing and wrong error message.

What happened to me was that I had not cleanly shut the disks down when using Windows XP and for some reason Ubuntu could not mount them. The force parameter to the mount command came to the rescue, like so:

mount -t ntfs-3g /dev/sdb1 /media/disk2 -o force

Your command will vary because your device name and mount name will be different. You’ll have /dev/<something> and /media/<something>. You may also need to change ntfs-3g to your drive’s type. But the important thing here is the -o force parameter – this tells the system to ignore the warning that stopped it mounting before and to bally well get on with it.

If you don’t know how to find out which device and mount point your system is using for your drive then keep your eyes peeled for a tutorial on here. You might even get a screenshot or two thrown in for good measure.

I need to get with the screenshot thing. If you read this far then reward yourself with a nice cup of tea and a sit down.

Gnome keyboard shortcuts

General Shortcut Keys

Alt + F1 Opens the Applicantions Menu .

Window Shortcut Keys

Alt + Tab Switches between windows. When you use these shortcut keys, a list of windows that you can select is displayed. Release the keys to select a window.

Panel Shortcut Keys

Ctrl + Alt + Tab Switches the focus between the panels and the desktop. When you use these shortcut keys, a list of items that you can select is displayed. Release the keys to select an item.

Application Shortcut Keys

Shortcut Keys Command
Ctrl + Z Undo
Ctrl + S Save
Ctrl + Q Quit

Gnome keyboard shortcuts

Below are some handy keyboard shortcuts for the Gnome desktop system. Use these and give your mouse a rest!

Alt + F1 Opens the Applications Menu
Alt + F2 Displays the Run Application dialog
Print Screen Takes a screenshot
Alt + Print Screen Takes a screenshot of the window that has focus
Ctrl + Alt + right arrow Switches to the workspace to the right of the current workspace
Ctrl + Alt + left arrow Switches to the workspace to the left of the current workspace
Ctrl + Alt + up arrow Switches to the workspace above the current workspace
Ctrl + Alt + down arrow Switches to the workspace below the current workspace
Ctrl + Alt + d Minimizes all windows, and gives focus to the desktop
F1 Starts the online help browser
Alt + Tab Switches between windows
Alt + Esc Switches between windows in reverse order

Switching out of fullscreen mode in rdesktop

rdesktop is a Remote Desktop Protocol client for linux – it enables you to remote desktop to a Windows machine.

It was difficult to find the keyboard shortcut for switching rdesktop in and out of fullscreen mode so I’m blogging this here so that others may find it (and to remind myself as I’m bound to forget).

The keyboard shortcut to toggle full screen mode in rdesktop is CTRL-ALT-RETURN

Removing multiple Ubuntu boot entries

If you are dual-booting Ubuntu with Windows you will have a bootmenu that allows you to select between the two systems.

When you first install Ubuntu you only have 3 options: Ubuntu <version x>, Ubuntu mem test and Windows XP/Vista/whatever.

Over time, when you upgrade Ubuntu, you can start to get multiple copies of the Ubuntu and Mem test options. This is a pain, particularly because the default option may no longer be what you want.

Luckily, fixing this is easy. Follow these steps:

1. Press Alt+F2. This brings up the Run application dialog.

2. In the dialog, type: gksudo gedit /boot/grub/menu.lst. This launches an editor to let you change the menu.lst file.

3. If prompted, enter your administrator password.

4. Once the editor has loaded, press Ctrl+f to open the find dialog.

5. Type howmany in the find dialog.

6. Look for the line in the file that reads howmany=all and change it to read howmany=1

7. Save the changed file and exit the editor.

8. That’s it. Next time you boot you will have only one Ubuntu option, one Mem test option and any Windows options.

Ubuntu announces Hardy Heron release

The Ubuntu team have announced that the release to follow Gutsy Gibbon (v7.10) is Hardy Heron (v8.04). Gutsy is due for release in October 2007 and Hardy is pencilled in for April 2008.

The Heron release will also include Long Term Support (LTS) – this guarantees security updates for the server version for 5 years after release and the desktop version for 3 years.