Moving Windows with the Title Bar Off Screen

In pretty much any operating system, if you want to move a window, you can click and drag the title bar of the window to move it. This shouldn't come as a surprise; in fact, you should probably be questioning why I'm even mentioning it. Well, what happens if you have a window open up and the title bar is off screen? If you use computers long enough, I promise, you will run into this scenario.

You are more likely to run into this situation if you are using a netbook with the standard resolution of 1024x600. I wouldn't call this a common event with my Mini 9, but I'll be honest, it's happened a few times. So, what can we do when we find ourselves in this situation? Well, it turns out that there are a couple of things that we can do:

  • Keyboard only method
    Your Linux distro should have a keyboard shortcut for moving windows. In Debian, the default is Alt + F7. To find out what the keyboard shortcut for moving windows is on your installation, open up a window (pretty much anything will do..nautilus, firefox, etc.). Then open the Window Menu for the window you just opened (keyboard shortcut here is Alt + Spacebar), and you should see this on the list. Now to move a window, you simply need to press the keyboard shortcut you found and then you can move the active window with the arrow keys. You can also simply move the mouse after pressing the keyboard shortcut, and when you click the mouse, the window will stay where you put it.

  • Keyboard and Mouse combination method
    There is another default shortcut for moving windows, and I find this one easier to remember. We simply need to hold the Alt key and click and drag anywhere on the window we wish to move to reposition it.

Now you should never have to worry about windows being positioned such that you cannot click and drag the title bar.

See you next time.


Bash Tutorial: Part 3

We're back at it with more about using Bash. This time, rather than focus on new commands, we'll look at command operators and redirection. Command operators allow you to run multiple Bash commands in one statement. Redirection is not just a useful tool when performing magic, it's also a great way to change where the input and/or output of a command come from and/or go.

Command Operators
  • ;
    To execute multiple commands one after another, we use the ; operator. In other words, the first command specified will run until completion before the second command starts. For example, if you want to update your index for the locate command and then search for the xorg.conf, we would do the following:

    # updatedb ; locate xorg.conf

    The above is essentially the same as running this:

    # updatedb
    # locate xorg.conf

  • &
    Executing commands in rapid succession all on one line is cool, but it can be more useful to run multiple commands all at the same time. For example, if you wanted to write a Bash script to launch firefox, pidgin, and songbird all at once, the important piece would be the following command:

    $ firefox & pidgin & songbird

    Another use for the & operator is if you want to run a command in the background. In other words, if you would like to run a command, but instead of waiting for the command to finish to regain control of the terminal, the control will immediately be returned and your computer will continue executing the command in the background. To do this, you simply end your command with &. If you wanted to update your index for the locate command, but don't want to wait for this to finish, you could do the following:

    # updatedb &

  • >
    Sometimes, the output of a command isn't immediately important, but you would like to save a record of it for later. To do that, we can use the > operator to create a new file, or overwrite an existing file, with the output of a command. For example, if you're trying to troubleshoot a networking problem, you might want someone to look at the output of the ifconfig command on your system. To save this output, you can do the following:

    # ifconfig > output.txt

  • >>
    Sometimes you want the output of a command to write to a file, but you don't want to lose the existing contents of that file. In this case, we can use the >> operator to append the output to the end of the specified file. For example, if you want to add the output of the lsmod command to the output file we just created, we could do the following:

    # lsmod >> output.txt

    If you have read some of my other posts, you have seen me use the two above redirection operators in conjunction with the echo command to create or add to files that control the behavior of some parts of the computer.

  • <
    There are also cases where you might want to specify the input of a command or program from a file. One example I can think of is if you have a text file that you would like to sort, you could use this as the input for the sort command like this:

    $ sort < unsorted.txt

    Of course, the above will simply output the text from unsorted.txt to the screen in sorted order. If we wanted to save the sorted version of the text file, we could combine input and output redirection to accomplish this:

    $ sort < unsorted.txt > sorted.txt

  • <<
    The << operator acts basically as a simple line based text editor. If you remember, we used it in the Installing Songbird post as an option for creating the Bash script to launch Songbird. Here's an example of the << operator with the sort command:

    $ sort << EOF
    > 3
    > 1
    > 2
    > EOF

    For another example, I've included the section where we used this in the Songbird post. In this example we use both input and output redirection to create a Bash script without dealing with a real text editor:

    # cat > /usr/share/Songbird/launcher.sh << EOF
    > #!/bin/sh
    > cd /usr/share/Songbird
    > ./songbird
    > EOF

  • |
    Pipes. Saving the best for last here, pipes allow you to redirect the standard output of one command to the standard input of another command. That may sound a little confusing as you read it, but let me give an example, that may clear things up:

    $ ls -al | less

    Using what we have learned about Bash command operators, the above command is basically the same thing as:

    $ ls -al > temp.txt ; less temp.txt ; rm temp.txt

    As you can see, piping commands is powerful and can save a bit of typing. My favorite use of pipes is with the grep command:

    $ ps -ef | grep firefox

    I'll cover both the ps and grep commands in future posts, but the above will give you information about any processes running on your system that have firefox as part of the process name. The above would be the same as the following:

    $ ps -ef > temp.txt ; grep firefox temp.txt ; rm temp.txt

That does it for Part 3 of the introduction to Bash.

See you next time.


Bash Tutorial: Part 2

For part 2 of my Bash tutorial, I didn't have the time to make it as big as I had wanted, so it's a little shorter. Let's get started.

Displaying file contents
  • cat
    Concatenate files. The cat command can be used to type out the contents of a file or of multiple files. To type out the contets of your /etc/apt/sources.list file, just do:

    $ cat /etc/apt/sources.list

    If you want to type out the contents of multiple files right after each other, just do:

    $ cat file1 file2 file3

  • less
    less is similar to cat for displaying the contents of a single file. However, less is much better than cat for large files. If you use cat on a large file, you will only be able to see the end of the file because the contents would have scrolled out of view and even beyond the scroll buffer. less allows you to scroll through the entire contents of the file with the up and down arrows as well as the page up and page down keys. To use less to display the contents of your /etc/apt/sources.list file, just do:

    $ less /etc/apt/sources.list

That's all for now. Next time we'll be back with part3.

See you next time


Bash Tutorial: Part 1

I know a lot of people get scared any time the command line comes up when using a computer. Really, the command line shouldn't be scary, and learning how to use the command line in any operating system will only make you better at using your computer. As such, I figured I would do a couple posts as an introduction into the Linux shell I use most: the Bourne-again shell (Bash). Let's get started.

Moving around the shell
  • pwd
    Print working directory. When you first open a shell, it starts you in your home directory, usually /home/[username], also abbreviated ~. If you're ever not sure what directory you're currently working in, the pwd command will tell you:

    $ pwd

  • ls
    List files. If you want to see what files and folders are in a directory, ls is the command to do it. If you just want to see the contents of the current directory, just use:

    $ ls

    In Linux, files whose name begin with . are hidden. To list the contents of the current directory and show hidden files, use:

    $ ls -a

    If you want to see more information about the files, such as who has permissions to read, run, and execute files; the owning user and group; the file size; and the last date modified, just use:

    $ ls -l

    The ls command does not simply restrict you to looking at files in your current working directory; you can look inside any directory you want. To see the long listing of all files in the /usr/bin directory, just use:

    $ ls -al /usr/bin

  • cd
    Change directories. Now that we've covered how to see your current working directory and listing files within directories, the next place to go is to change directories. In order to change directories to /etc/X11, just do:

    $ cd /etc/X11

    We can also use .. to move up a level:

    $ pwd
    $ cd ..
    $ pwd
    $ cd ../..
    $ pwd
    $ cd ../2.6.26-1-686
    $ pwd

Working with files
  • cp
    Copy. The basic syntax for the cp command is:

    $ cp [source file] [destination file]

    For example, if you wanted to make a backup copy of your .bashrc file before making changes:

    $ cp .bashrc .bashrc-backup

    This is a good for copying single files, but if you want to make a copy of an entire directory, we can use the -r option to do a recursive copy:

    $ cp -r Documents Documents-backup

  • mv
    Move. The mv command works similar to cp:

    $ mv [source file] [destination file or directory]

    If you want to simply rename your .bashrc-backup file to fix edits made to your .bashrc file:

    $ mv .bashrc-backup .bashrc

    If you want to move a file into a different directory:

    $ mv .bahsrc-backup Backup/

    If you need to move or rename a directory, it works exactly the same with the mv command as moving files.

  • mkdir
    Make directory. If you want to create a new directory for all your digital pictures, just do:

    $ mkdir Pictures

    You can also create a any missing parent directories with the -p option:

    $ mkdir -p Pictures/Vacation/2009

  • rm
    Remove. If you want to delete the .bashrc-backup file, just do:

    $ rm .bashrc-backup

    If you want to delete a directory and all the files and subdirectories within it, you can use the -r recursive option:

    $ rm -r /Pictures/Vacation/2009

  • rmdir
    Remove directory. If you want to delete a directory, you can use the rmdir command. The rmdir command requires that the directory that you're trying to delete is empty:

    $ rmdir Pictures/Vacation/2009

    Similar to the recursive option that we've seen with other commands, we have the -p parents option to use with rmdir:

    $ rmdir -p Pictures/Vacation/2009

    The above behaves the same as the following:

    $ rmdir Pictures/Vacation/2009
    $ rmdir Pictures/Vacation
    $ rmdir Pictures

Learning more

We've covered a lot in this post, but there is still more that can be done with the above commands. Here are some resources that are available to learn more of the options available.
  • man
    Manual. The man command will bring up what is called the "man pages" for other commands. The man pages describe the syntax and available options for bash commands and programs. The syntax for man is as follows:

    $ man [command]

    So, if you wanted to see more information about the cp command:

    $ man cp

  • info
    Information. The info command is similar to the man command, but the info pages can be a little easier to learn from if you're not used to reading man pages. If you want to see the info page for the cp command:

    $ info cp

That does it for Part 1 of the introduction to Bash.

See you next time.


Scheduling Commands with Crontab

A common thing to want to do is to schedule a command to run at a specific time. We can do with with cron using the crontab command. By default, all users have permissions to use crontab; however, this can be changed by the existence of one of two files:
  • /etc/cron.allow - Only users listed in this file can use crontab
  • /etc/cron.deny - Users listed in this file cannot user crontab

To see what you have scheduled via crontab, you can run the following command:

$ crontab -l

If you want to see what is scheduled to be run as a different user, you can use the following:

# crontab -u [username] -l

Where you would replace [username] with the appropriate username. Entries in the crontab file have the following syntax:

[m] [h] [dom] [mon] [dow] [command]

Now, I'll explain the above:
  • [m] - Minute to run; represented as a number: 0-59
  • [h] - Hour to run; represented as a number in: 0-23
  • [dom] - Day of Month to run; represented as a number: 1-31
  • [mon] - Month to run; represented as a number: 1-12
  • [dow] - Day of Week to run; represented as a number: 0-6 (Sunday is 0)
  • [command] - Command to run

All of the timing options above can be replaced by an * where necessary to have your command run for all possibilities of that option. For example, in my post on locating files I mentioned scheduling the updatedb command. Let's say we want to schedule this command to run every morning at 6:30 am, then we would put the following into the root user's crontab file:

30 6 * * * updatedb

You can also use a comma separated list for the timing options to have a command run at multiple timings. For example, I have the bad habit of staying on my computer too late at night when I should be going to bed. To try to correct this, in the past, I have scheduled my computer to shutdown at 11:00 pm on Sunday through Thursday nights:

55 22 * * 0,1,2,3,4 shutdown -h +5

Now that we see the necessary syntax for entries in the crontab file, how do we use the crontab command to edit the file to schedule our commands? We can use the following to create or edit a user's crontab file:

$ crontab -e

The above will open your current user's crontab file in the current user's default text editor. Once here, you simply need to put in the entries you would like using the above syntax to schedule them. There are some other options that you can use with the crontab command:
  • -l [username] - Displays [username]'s crontab file
  • -r [username] - Removes [username]'s crontab file
  • -u [username] - Runs the specified contab command on [username]'s crontab file

That pretty much does it for a basic introduction to scheduling commands with crontab.

See you next time


Finding Files on Your Computer

It happens to all of us, we forget where files are saved. The good news is that with the locate command is a great way to find files on your computer. Before we can use the locate command, we've got to build an index of the files on our computer, which is easy enough: we just need to use the updatedb command:

# updatedb

It is a good idea to periodically run the updatebd command to keep your index current when you go to search for files. All you need to know to search for files is to know all or part of the file name. For example, if you couldn't remember where the xorg.conf file is saved, you can search for it like this:

$ locate xorg.conf

Here is an example output of the above command:

$ locate xorg.conf

Alternatively, if you were looking for the xorg.conf file, but could only remember that the filename started with xorg., you could search for it like the following:

$ locate /xorg.

There is more that can be done with the locate command, but this has covered about 98% of the times I've used it. I'll probably cover some more of these features in a later post. Another thing that is useful is to schedule the updatedb command via cron, which we'll be discussing next time.

See you next time


Turn Off Your Laptop Display

One thing I find inconvenient about laptops is that they typically do not have a power button for the display the way standard monitors do for desktop computers. It turns out that if you have ACPI enabled in your kernel, there's an easy way to create a keyboard shortcut to turn off your laptop display.

First thing, we can test to make sure this will work by running the following command:

$ xset dpms force off

That should turn off your laptop monitor until you move the mouse or type on the keyboard. Now to assign the keyboard shortcut, we need to open the configuration editor with the following command:

$ gconf-editor

You'll want to navigate the tree view on the left to the following path: /apps/metacity/keybinding_commnads. In the right panel you'll see that it lets you assign 12 commands (numbered 1 through 12). Just pick an empty one and assign it the following value:

xset dpms force off

Next you will want to find the following path on the tree view on the left: /apps/metacity/global_keybindings. Here you will see entries named run_command_x for x between 1 and 12. You will want to find the command that you edited earlier and in the Value space, type in the shortcut you want to run this with. For example, on the Mini 9, since Sleep is mapped to Fn+1, I decided to map this to Alt+1. To do this, I used the following value:


Once you do that, you can test your keyboard shortcut and then close out of the configuration editor.

See you next time.


Convert Raster Graphics to Vector Graphics

Have you ever wanted to convert a raster image (.jpg, .png, etc.) to a vector image (.svg)? Maybe not yet, but in my post on Installing Songbird, when we added Songbird to the menu, we did not have an icon to set for the menu item. It turns out that this is because we need a .svg image and the Songbird tarball only came with a .png image. No worries, though, we'll go through converting raster to vector and, specifically, how to convert the songbird.png image to a vector image for use on our menu.

In order to do this, we're going to make use of two programs: ImageMagick and Inkscape. ImageMagick is a powerful command line utility for all kinds of graphics manipulations. Inkscape is more widely known as an open source GUI vector graphics editor; however, it also comes with its own set of command line tools. Let's make sure we have these two programs installed:

# apt-get update
# apt-get install imagemagick inkscape

While it is possible to do this though the Inkscape GUI, I find the whole process easier and faster right from the command line. We will use ImageMagick to resize images, if necessary (refer to my first ImageMagick post if you have questions about resizing images with ImageMagick), and we will use Inkscape to do the actual conversion. The command to do the actual conversion is actually very simple:

$ inkscape InputImage.png --export-plain-svg=OutputImage.svg

When you run this command, expect to see a message similar to the following:

(inkscape:30498): GLib-GObject-CRITICAL **: g_object_set_qdata_full: assertion `quark > 0' failed

This is OK, your image still got converted. Now, let's use this to get the songbird.png image in place for use on our menu. Let's start by copying the songbird.png image into out home directory to make things easier:

$ cp /usr/share/Songbird/songbird.png ~/

Now we can use the mogrify command to resize this to a 48x48 pixel image and then use the inkscape command to convert this to songbird.svg:

$ mogrify -resize 48x48 songbird.png
$ inkscape songbird.png --export-plain-svg=songbird.svg

Now, we'll just copy our new songbird.svg image into the same directory as all the other menu icons:

# cp songbird.svg /usr/share/icons/hicolor/scalable/apps/

If we set up Songbird in your menu the way I described before, then all we will need to do is to restart X (Ctrl + Alt + Backspace) and our new songbird.svg image should should show up in our menu.

See you next time