Friday, February 26, 2010

Useful command line little tricks (part 3)

On this third part of these series, I wanted to cover some system and hardware topics. My idea was to provide a bit of information around the interpretation of Linux system logs, system commands, hardware recognition, etc. On this specific blog entry, I'd like to cover the lshw command and how to get information from it.

HAVING FUN WITH LSHW

This command essentially allows for listing hardware, as recognized by your machine. It can be very useful for troubleshooting, in case a system device was not recognized or configured properly. In addition, it is an extremely thorough report, so you may find information about your machine you didn't even know yourself!

It is precisely because of that tendency from lshw to provide such amount of information that you may want to narrow it down in the long run. For the time being, let's just run lshw as is:

lshw

If you run this command under Ubuntu, you will receive a warning, asking you to run it as an administrator. This is a recommendation, you are still allowed to run it using your standard credentials. This is not the case in other distros, so you may be forced to sudo this command, or run it as root.

The output you will obtain is a full list of your hardware, which is hard to check in such command line output format. There are several things you can do to make it easier. For example, you can pipe this output to less, thus allowing for scrolling throughout.

lshw | less

You could also redirect the output from lshw to a file, like this:

lshw > hardware_list.txt

If you just want to take a quick look, but don't want to keep the file created, you can chain commands in one line, like this:

lshw > hardware_list.txt ; gedit hardware_list.txt ; rm hardware_list.txt

This way of sequencing commands is pretty convenient, right!?

FILTERING LSHW OUTPUT

As you have surely realized, lshw output is long and very thorough. In real life, you may only be interested in reading a portion of it. Let's see ways in which we can filter lswh output.

One of the most convenient ways to narrow down the information we get from lshw is taking advantage of its own classes. Here's a list of the classes available:

- Bus
- Memory
- Processor
- Bridge
- Display
- Multimedia
- Network
- Storage
- Communication


Now, to get information for a specific class, run lshw as follows:

lshw -C processor

In this example, I listed information for the "processor" class. Note that you should use lower case syntax for class groups.

As you probably know, we can combine all of the filtering tools we have seen so far in order to create a more complex command that provides more functionality:

lshw -C processor | tee processor_list.txt | grep -i 'Vendor' > vendor.txt ; gedit vendor.txt; rm vendor.txt

In this example, we are creating a file named 'processor_list.txt', which contains all info regarding the processor class. We can do this by using the tee command, which allows us to pipe the output from a command into a file and into the next pipe. Then we filter this output further and obtain the information about our CPU manufacturer, which we redirect to a file. We then display it on gedit, then remove the file after we close the text editor.

As we have seen in recent examples, there are better ways to display the information in the GUI than creating a file, opening it with a visual text editor and then closing and removing the file. The zenity command is perfect for this, here's how it would work with it:

zenity --info --text "Your CPU manufacturer is: $(lshw -C processor | grep vendor | cut -c 16-)"

As you can see from the screenshot below, this is a more elegant way of getting that kind of info. Also note that the string format manipulation I do with the cut command is just a "quick and dirty" solution. A script could easily work around this and customize zenity output according to user input.



Obviously, I am not covering here all of the options available for lshw, but I hope you found it interesting and useful. Linux is all about imagination and creativity. The options are there for you and it is up to you how to get the most out of them.

Good Luck & Enjoy!

Monday, February 22, 2010

A simple security script

Not long ago I wrote about the misconceptions around Linux invulnerability to virus and malware. Linux is indeed not 100% safe, as was described on THAT ENTRY.

If you are a Linux user and are not aware of such security threats, I very much encourage you to read that entry. If you have, you will likely remember I shared a simple script that would help in checking the content of those shortcut files that could potentially be so harmful. That script was obviously a disaster, a result of my lack of experience and command line skills... (But hey, I tried! ;-) )

I want to share a slight modification of that script, a more elegant way of doing the same thing, both for KDE and GNOME users. Here it goes:

1.- Start by creating a script file on a location of your choice. I recommend you do so at your home folder, so my example will base on that. You can use the text editor of your choice, from the GUI or CLI. I like using gedit.

gedit security_check

2.- Now, enter the following code:

GNOME USERS

zenity --info --text "$(less ~/.local/share/applications/*.desktop | grep Exec)"

KDE USERS

kdialog --title "Security Check" --passivepopup "$(less ~/.local/share/applications/*.desktop | grep Exec)"

3.- Save your script.

4.- In order to be able to trigger it from a shortcut, as I will be covering in this example, you need to modify your script privileges, so it can be executed. Since you are the owner of the script, it is pretty simple:

chmod 744 security_check

5.- You are all set now, just need to create a shortcut from which you can trigger this simple script. Here's how I did it:

GNOME



KDE



And here's what you will see when the script runs:

GNOME



KDE



Obviously, you could also automate the triggering of these scripts, perhaps when your session starts, perhaps as a scheduled task, etc. I will leave that at your discretion, but I do encourage you to run this little script every now an then to ensure none of those ".desktop" shortcuts is doing something nasty.

Sunday, February 21, 2010

GNOME wins by the smallest margin!

Yes, the poll time is now over and Gnome finished in the lead, all be it leading by the smallest margin!

Here are the final results:
GNOME             14 votes (43 %) 
KDE               13 votes (40 %)
XFCE              2 votes (6 %)
ENLIGHTENMENT     0 votes (0 %)
OTHER             3 votes (9 %)
Thanks to all who voted!

Friday, February 19, 2010

Missing GDM??

If you used Ubuntu before the last 9.10 Karmic Koala release, or if you used other distros before, you may have realised the lack in functionality in GDM as you moved to this latest release. Essentially, the previous versions of GDM were a lot more customizable, allowing users to change their login screens as they pleased through the use of themes.

In addition, on top of the loss of functionality, the guys at Ubuntu have come up with a very serious and profesionally looking GDM default theme, which obviously didn't do it for everybody. People liking colorful login screens, or the ability to change them every now and then, were frustrated by this situation.

SUFFER NO MORE, FOR GDM2 IS HERE!

GDM2 is a login interface management utility for the new GDM. Among other features, GDM allows for wallpaper customization, autologin option and prompted or userlist login. If you want to give it a try, do the following (instructions specific to Ubuntu 9.10 Karmic Koala):

From the command line, run the following commands:

    sudo add-apt-repository ppa:gdm2setup/gdm2setup

    sudo apt-get update

    sudo apt-get install python-gdm2setup
Just to clarify, the steps above simply import a new PPA, update your repository list and then install the GDM2 application.

That should do it. You should now see a new menu item labeled "Login (GDM2Setup)" under System > Administration.

Good luck and happy GDM'ing!

Tuesday, February 16, 2010

Useful command line little tricks (part 2)

In the first part of this series, we discussed a bit about the folder structure, an important element in understanding Linux foundations. Today I want to concentrate on commands specific to process management and monitoring.

PROCESS MANAGEMENT AND MONITORING

If you have used the process monitor under Ubuntu, you know how good an application it is, but there are very useful shell commands you can use. The top and ps commands are both very useful, certainly incorporating more information and requiring less system
resources. Simply type the following:

top

You will see a neat table usually displaying a system information summary and about 20 processes. As you will quickly realize, this command displays processes in real time, refreshing the list every few seconds. To begin with, let's take a quick look at that system information summary displayed on top of the list, which provides lots of useful information, as can be seen on the following picture:



Starting from the first line, from left to right, we see the command name, the system time and the amount of time since the system was booted. Moving on, we can see how many users are currently running processes in the system, and then the average of processes waiting to run split in three time periods: 1, 5 and 15 minutes. The next row displays info about system tasks. CPU information awaits on the next row, starting with current load, then showing how much of it is used by system, nice (low priority), iddle, and awaiting processes. The next two rows display memory information. Simply type "q" to quit the top command and return to the system prompt.

You can narrow down the output from top in order to more comfortably display the information you are after. There are a number of different ways to do so, here are some examples:

top | grep swiftfox

In this example, I am using pipes to filter the outcome from top using grep, which displays only rows containing the word "swiftfox". You could also display only those processes you are interested in, by process id.

top -p9999 -p1111 -p2222

The example above would limit the output from top to only the processes with ids 9999, 1111 and 2222. You can add as many process ids as you want.

Another very useful process related command is ps. When run on its own, it apparently returns useless information:

ps

Output would return something like this:

PID    TTY      TIME CMD
7705   pts/0    00:00:00 bash
14522  pts/0    00:00:00 ps

This is because it is only showing processes from the current virtual terminal, which runs two commands, bash and ps. In order to display all processes, use it as follows:

ps -A | less

Because of the length of the list returned, I am piping it to the less command, so the output can be scrolled throughout. Once again, type "q" to exit less and return to the prompt.

ps -C swiftfox

In the example above I use the -C parameter to show processes by process name. In this case, I am using the process "swiftfox". Here's the resulting output:

PID    TTY      TIME CMD
532    ?        00:00:00 swiftfox

It is interesting to use the -f parameter, which displays full format. Combined with the -A (or -e) parameter, we get all of the processes in such format. Once again, we can benefit from piping output into the grep command to narrow down its input.

ps -Af | grep ps

The command above would return the following:

shred     7705  7702  0 20:57 pts/0    00:00:00 bash
shred    17920  7705  0 22:09 pts/0    00:00:00 grep bash

Finally, let's see how to terminate processes with the kill command.

sudo kill 9999

The example above would send a terminate signal to the application whose process id is 9999. This is equivalent to using the parameter 15, like this:

sudo kill -15 9999

Once again, this would send a terminate signal to the application, which would be handled at application level. There is a more extreme option, which terminates the process at kernel level. This option should only be used as a last resort if the default option does not work:

sudo kill -9 9999

And that is it for this second part of this series, specifically covering process management commands.

Enjoy!

Saturday, February 13, 2010

Install OpenOffice 3.2 in Ubuntu

Hey, I thought I'd share a step by step tutorial on how to install the OpenOffice.org latest release. Just follow these simple steps:

Before you do anything, I recommend uninstalling your current OpenOffice installation. You can easily do so by running the following command from the shell:

sudo apt-get remove openoffice*.*

1.- Download the required deb file from the OpenOffice.org WEBSITE

2.- Now, extract the contents from the deb file you just downloaded (OOo_3.2.0_LinuxIntel_install_wJRE_en-US_deb.tar.gz) into your home folder. You can do so by using your choice of uncompressing software from the GUI or by running the following command from a virtual terminal:

tar xzvf OOo_3.2.0_LinuxIntel_install_wJRE_en-US_deb.tar.gz

3.- You should now see a folder named OOO320_m12_native_packed-1_en-US.9483. To get the installation moving, use the following command, once again from a virtual terminal:

sudo dpkg -i ~/OOO320_m12_native_packed-1_en-US.9483/DEBS/*.deb

4.- Once the command above has completed (may take a few seconds), run the following:

sudo dpkg -i ~/OOO320_m12_native_packed-1_en-US.9483/DEBS/desktop-integration/openoffice.org3.2-debian-menus_3.2-9472_all.deb

That should be it!! You can now enjoy the latest and greatest from OpenOffice.org, and judging by the few minutes I had toying with it, it is very promising!

Credit goes HERE

Thursday, February 11, 2010

Openshot: A Linux video editor

I just found about Openshot, a recent addition to the list of Linux video editors, and from what I can see, it is awesome. I am by no means a video editing expert, but I have seen the screenshots, videos, as well as the list of features, and this application seems to have LOTS of potential.

Check it out and visit their OFFICIAL SITE

Wednesday, February 10, 2010

New KDE.org site and KDE SC 4.4 Release!

Brief entry to discuss some great news from the KDE camp!

YES!!! KDE SC 4.4 codenamed "Caikaku" is out now!. The much expected new version of this successful desktop manager is live now and available for download. The guys at KDE.org have put together a very cool announcement page, with videos that highlight some of the many new and exciting features Caikaku will bring to all KDE users. I very much encourage you to CHECK IT OUT!!

They have also released a brand new website, and it looks COOL.

Enjoy!

Monday, February 8, 2010

Useful Command line little tricks (part 1)

Before I started using Linux, I never really understood why people would use the command line, much less why they would consider it such a powerful tool. I always thought I could do just as much from the GUI, and even quicker. Sadly, I have come to an understanding quite late, but as they say, "better late than never"!

Ultimately, if you use the GUI, you learn to use that interface, but you are missing on how the OS actually works. Believe me, when you start getting an understanding on how the system works and what it does, when you start to get where to look when something fails or what to change in order to fix it, that's when you experience a great feeling of empowerment. On top of that, the GUI is great for certain activities, but it is very limiting when it comes to others.

Obviously, I am sure you have read very similar statements before, and none have convinced you to actually learn to use the command line. Guess what? I am not going to try to. All I want to do is explain some of the basics. If after reading this you feel you are the kind who might enjoy understanding how the computer does what it does, then you might actually want to jump into the cold waters after me. Otherwise, I hope this was not too boring!

First off, I want to provide some background about the shell as it stands in Linux today. I also want to share some interesting commands I use regularly, which might help you as well. Let's start with some basic concepts:

WHAT IS BASH?

BASH is a command interpreter that is widely extended in the Linux world. It is the GNU reinterpretation of the Bourne Shell (an important early UNIX shell created by Stephen Bourne). In fact, Bash is an acronym, a pun on the name Bourne Shell and the term "born again", thus Born Again SHell.

THE LINUX FOLDER STRUCTURE

If you run this simple command,

ls /

you should get your basic folder structure under the root directory, looking something like this (displayed as a list here for formatting reasons):

bin
boot
cdrom
dev
etc
home
initrd.img
initrd.img.old
lib
lost+found
media
mnt
opt
proc
root
sbin
selinux
srv
sys
tmp
usr
var
vmlinuz
vmlinuz.old


Let's see what some of those folders are used for in Linux. Understanding the basic folder structure will help you in seeing the big picture!

BOOT folder

Contains the Kernel, some drivers that may be required at boot time, and the boot loader. In the current version of Ubuntu, that turns out to be GRUB2. For example, if you wanted to take a look at the GRUB2 script that controls the boot of your system, you can do so by running the following command (note that this file is not meant to be manually edited):

less /boot/grub/grub.cfg

DEV folder

Contains a list of all the devices (actually, device nodes) recognised by the kernel. For example, your hard drive is mounted under one of these nodes, most probably SDA1. For a list of all device nodes, you can run the following command:

ls /dev

ETC folder

Contains system wide variables, such as passwords, information about file systems, and even your repository sources. You may have actually edited those sources manually already, but if you have not, you could do so by running the following command:

sudo gedit /etc/apt/sources.list

You could obviously run it with any other visual text editor, or even with nano or vi, whatever your preference.

HOME folder

Here's where ordinary users folders are stored, and for the most part, it will be the only location you have rights to modify in a properly configured Linux system. This is actually one of the features showing the strength of Linux security. As opposed to Windows, where any user can go ahead and save or modify files under C:\windows\system32, for example, nobody can do such changes in Linux out of the box.

MEDIA folder

Here's where modern Linux systems mount removable drives. USB external drives, CD and DVD devices... They all are listed under this folder.

OPT folder

Optional software is stored in here. As an example, I have Adobe AIR and TweetDeck stored under this folder.

USR folder

Contains general applications used by standard users. It usually is a very large folder, as it contains hundreds of applications. Some interesting folders under the USR one include the BIN folder, which contains the applications themselves and the LIB folder, which holds documentation for those applications.

USR/SHARE folder

This folder deserves a bit more attention due to the useful information it contains. It basically holds shared data used by applications under /usr/bin. For example, you can find your system icon themes under /usr/share/icons/themes.

VAR folder

The information that is likely to change is stored under this folder. For example, we can find logs, which are stored under the log folder. In order to take a quick glance at the latest changes in your system log, you can try the following command:

less /var/log/syslog

You can also check boot logs to check if you had issues when starting up your machine:

less /var/log/boot

TO BE CONTINUED...

Let's stop here, as there is a lot of information already for you to digest!. I very much encourage you to investigate your system folder structure. Understanding its logic will get you closer to understanding your system, which is already quite a step forward.

In the next installment of these series, I will cover some commands that I often use. I hope you find them just as useful!

Wednesday, February 3, 2010

Ubuntu 9.10 Karmic Koala wins!

Yes, folks, Ubuntu 9.10 finished first in the "which of the latest linux distros do you like best?" survey.

These are the final results:

1.- Ubuntu 9.10 - 29 votes (39%)
2.- Fedora 12 - 20 votes (26%)
3.- Mandriva 2010 - 10 votes (14%)
4.- Linux Mint 8 - 9 votes (12%)
5.- OpenSuSE 11.2 - 7 votes (9%)

I just set up a new survey, with desktop managers this time. Which one do you like best?

Tuesday, February 2, 2010

XMMS music player

If you liked Winamp and thought you had to stop using it under Linux, well, think again. XMMS is a very light yet powerful audio player that looks and works very similar to Winamp.

When you install Ubuntu from scratch, there is no such thing as a light audio specific player pre-installed. There is Rhythmbox, of course, but it is not particularly light, and it is actually more of an attempt to mimic iTunes functionality, rather than a small and light player. Honestly, I always loved that in Winamp, one of those few applications that does what it is meant to be doing, quick and right.

Eventually I decided to install XMMS in my USB Ubuntu installation. Being USB based, it was struggling a bit when I was running Songbird, which is kind of a heavy application. On top of that, since I am using an 8GB USB drive, I can't really store loads of music in it, so what's the point in having an application like songbird that can manage music libraries, show CD covers, pull down artist info and song lyrics?

I decided I would be better off just running a very light audio player that would play my music after a simple double click. Here's how XMMS looks:



Well, actually, that's just one of its many skins!!!!

Now, to install XMMS on an Ubuntu machine, you simply need to add the XMMS repositories. For other distros, visit XMMS OFFICIAL SITE for further details.

In order to add the XXMS repositories, you can do so from the GUI, just go to System menu > Administration > Software Origins. Alternatively, you can do so from the command line, typing the following command:

sudo gedit /etc/apt/sources.list &

Then, scroll down to the end of that file and add a couple of lines as specified below, depending on your version of Ubuntu:

Ubuntu Jaunty 32- and 64-bit x86

deb http://www.pvv.ntnu.no/~knuta/xmms/jaunty ./
deb-src http://www.pvv.ntnu.no/~knuta/xmms/jaunty ./


Ubuntu Karmic 32- and 64-bit x86

deb http://www.pvv.ntnu.no/~knuta/xmms/karmic ./
deb-src http://www.pvv.ntnu.no/~knuta/xmms/karmic ./


Now save and close the file sources.list.

If you added these repositories from the GUI, you will be automatically asked for updating sources. If you ran it from the command line, do so as follows:

sudo apt-get update

Now, let's install XMMS. You can once again choose to do so from the GUI, using the package manager of your choice. From the command line, just type the following:

sudo apt-get install xmms

Now that we have installed XMMS, let's use it! Unfortunately, in my experience, the installation of XMMS does not create any launcher in the Applications menu or in the desktop, so you will need to create one.

In order to create a launcher in Applications menu, go to System menu > Preferences > Main menu. Select the Sound and Video section and click on the "New item" button. Then, enter the application description, the application command and finally choose a custom icon if you please. You can use the screenshot below as a reference:



Now, I usually enjoy double clicking on an MP3 file and having it play on XMMS, instead of opening XMMS and opening the song I want to hear. In other words, I like having XMMS as my default MP3 player.

If you like that feature as well, you need to set up your music file extensions to run XMMS by default. In order to do so, right click on an MP3 file, click on "Properties", then go to the "Open with..." tab. XMMS might not be on the list. If the case, click on the "Add" button and add it. You may need to enter the command itself if it can't be found in the list of available applications.

If you are like me, you like having many look & feel options at hand, so let's download some skins. There is a great collection of skins available HERE. In order to be able to use those skins, extract them into the following folder:

/home/YourUserID/.xmms/Skins

Now you can change skins by simply right clicking on XMMS itself, going to Options menu > Skin browser.

That should be it, I hope you enjoy XMMS as much as I do!

Cheers

EDIT (08/02/2010): I was a bit frustrated that I could not right click on a music file and enqueue it, as I have always done with Winamp. I thought it could not be so difficult, so I went and checked the options available for the XMMS application. From a terminal emulator window type the following:

xmms --help

As you can see from that list, there is an option (as expected) that allows us to do just what we're after:

-Q, --queue
Add file(s) to playlist and queue


So now you simply need to repeat the process described above to add XMMS to the list of applications available to open MP3 files with, only calling XMMS with this option this time. When you are done, you should see a main "Open with XMMS" option at the top of the menu (same we had already). In addition, you should see another entry for this option below, as an alternative program to open MP3 files with. You should be able to enqueue files with that option.

Give it a try and let me know if something does not go as expected!