Linux For Cynics One user's experiences with Linux

19Apr/130

Check your Laptop Battery Status from Command Line

The tool used to query laptop battery state is called acpi. In Ubuntu or Debian, install it like so:

$ sudo apt-get install acpi

Let's run it!

$ acpi

The output looks something like this:

Battery 0: Discharging, 99%, 02:34:33 remaining

There are various options for acpi we can use:

Check the temperature:

$ acpi -t

Output:

Thermal 0: ok, 48.0 degrees C
Thermal 1: ok, 48.0 degrees C

To check the AC power status

$ acpi -a 

Output:

AC Adapter 0: off-line

You can check all the status together:

$ acpi -V

Output:

Battery 0: Discharging, 96%, 02:33:55 remaining
Battery 0: design capacity 1773 mAh, last full capacity 1723 mAh = 97%
Adapter 0: off-line
Thermal 0: ok, 48.0 degrees C
Thermal 0: trip point 0 switches to mode critical at temperature 105.0 degrees C
Thermal 0: trip point 1 switches to mode passive at temperature 90.5 degrees C
Thermal 1: ok, 47.0 degrees C
Thermal 1: trip point 0 switches to mode critical at temperature 127.0 degrees C
Cooling 0: LCD 8 of 15
Cooling 1: Processor 0 of 10
Cooling 2: Processor 0 of 10
17Apr/130

Change the Hostname (Computer name) in Ubuntu

Changing your computer's name (also called the system's "hostname") in Ubuntu is simple. You just have to change two files and restart the computer. These instructions also work for Debian and Ubuntu-based distros (like Linux Mint). The files in question are /etc/hosts and /etc/hostname

1. Open /etc/hosts with sudo (or gksu if you're going to use something like gedit)

$ gksu gedit /etc/hosts

The file will look something like this:

127.0.0.1       localhost
127.0.1.1       current_hostname

Instead of current_hostname you'll see the hostname / computer name. Change it to whatever you want the new name to be. Save and close the file.

2. Open /etc/hosts with sudo (or gksu if you're going to use something like gedit)

$ gksu gedit /etc/hostname

This file just contains the hostname / computer name. Change it to whatever you want the new computer name to be. Make sure it matches the name you put in /etc/hosts. Save and close the file.

3. Restart your computer.

Tagged as: , No Comments
12Apr/131

Using rxvt-unicode-256color with ssh and screen

urxvt is one of the best terminal emulators available, however it comes with problems. For example, if you use ssh to connect to a remote host and then try to use screen, you might get an error like this:

Cannot find terminfo entry for 'rxvt-unicode-256color'.

The work around for that is to add this line to your ~/.Xdefaults or ~/.Xresources file (I used .Xresources):

URxvt*termName: rxvt

This will make urxvt identify as rxvt, which should work with screen.

10Apr/130

Determine What Version of a Package is Installed on Ubuntu or Debian

If you want to find out what version of a package you have installed, dpkg will give you information concerning a package, including the version, if you use the "--status" option, like so:

$ dpkg --status packagename

where packagename is the package in question.

Now, it gives a lot more than the version.
For example,

$ dpkg --status openbox

Returns:

Package: openbox
Status: install ok installed
Priority: optional
Section: x11
Installed-Size: 1316
Maintainer: Debian QA Group 
Architecture: i386
Version: 3.5.0-7
Provides: x-session-manager, x-window-manager
Depends: libc6 (>= 2.2), libglib2.0-0 (>= 2.24.0), libice6 (>= 1:1.0.0), libobrender27 (>= 3.5.0), libobt0 (>= 3.5.0), libsm6, libstartup-notification0 (>= 0.7), libx11-6, libxau6, libxext6, libxinerama1, libxml2 (>= 2.7.4), libxrandr2, libxrender1
Pre-Depends: dpkg (>= 1.15.7.2)
Recommends: openbox-themes, obconf
Suggests: menu, ttf-dejavu, python, libxml2-dev
Breaks: menu (<< 2.1.12)
Conffiles:
 /etc/menu-methods/openbox 454ed1e8309e6fc60b0d16894d541dfd
 /etc/xdg/openbox/menu.xml 96647f77053f8d73987a6e2b77b18e8f
 /etc/xdg/openbox/rc.xml da6375c910abc7dfb69f26b6bd7deb70
 /etc/xdg/openbox/environment 34bbf463555dbfb8f97fe957489d73b7
 /etc/xdg/openbox/autostart 2e828424c93a51d910382b53a9729166
Description: standards compliant, fast, light-weight, extensible window manager
 Openbox works with your applications, and makes your desktop easier to manage.
 This is because the approach to its development was the opposite of what seems
 to be the general case for window managers.  Openbox was written first to
 comply with standards and to work properly.  Only when that was in place did
 the team turn to the visual interface.
 .
 Openbox is fully functional as a stand-alone working environment, or can be
 used as a drop-in replacement for the default window manager in the GNOME or
 KDE desktop environments.
 .
 Openbox 3 is a completely new breed of window manager.  It is not based upon
 any existing code base, although the visual appearance has been based upon
 that of Blackbox.  Openbox 2 was based on the Blackbox 0.65.0 codebase.
 .
 Some of the things to look for in Openbox are:
 .
  * ICCCM and EWMH compliance!
  * Very fast
  * Chainable key bindings
  * Customizable mouse actions
  * Window resistance
  * Multi-head Xinerama support!
  * Pipe menus
Homepage: http://www.openbox.org

So, to only see the version, just pipe the output of dpkg -status to grep, for example:

$ dpkg --status openbox | grep 'Version'

will output something like this:

Version: 3.5.0-7

Note, dpkg --status packagename can be replaced with any of the following:

$ dpkg -s packagename
$ dpkg-query --status packagename
$ dpkg-query -s packagename
Tagged as: , No Comments
3Apr/130

Which Architecture

A common question a lot of new users have is, what is an "architecture" and which one does my computer use?

If you really want to know what is meant by computer architecture, then there's always wikipedia to learn from.

In the context of Linux users, I usually hear this question in a couple different scenarios:

Q: I want to install a Linux distribution, which version do I need, 32 or 64 bit?

A: You can't go wrong by installing a 32 bit distribution, because hardware designed to run 64 bit software, can run 32 bit software with no problem. Here's a list of 64bit CPUs. If your CPU is on your list, you might want to use a 64 bit version of your distro instead. A little tip: If you really need to ask this question and the answer confuses you, just go with the 32 bit version.

Q: I already have Linux running on this machine, now I want to know if it's a 32 bit kernel, or a 64 bit kernel.

A: Easy!

uname -m

will give you the architecture of your kernel. i386, i686 are 32 bit, and amd64 is 64 bit!

Q: Okay, how do I find out if my CPU is 32 or 64 bit, regardless of what Linux kernel it's running?

A: There are actually a few ways to do this:

lscpu

displays cpu info, and will tell you the architecture of your CPU and if it can use 64 bit op-mode. This is probably the easiest way.

Another way:

grep lm /proc/cpuinfo

searches for the "lm" string in /proc/cpuinfo/. If it's found, that means the CPU is capable of 64 bit mode. Btw, lm means "long mode".

Tagged as: No Comments
29Mar/130

Using pkg-config to Find Library Names

If you are trying to use a library in your program, of course you need to link with it. How do you know what it's called? Use pkg-config! From the pkg-config man page

The pkg-config program is used to retrieve information about installed libraries in the system. It is typically used to compile and link against one or more libraries. Here is a typical usage scenario in a Makefile:

program: program.c
cc program.c $(pkg-config --cflags --libs gnomeui)

Here are some common usages:

List all installed libraries:

pkg-config --list-all

List what compiler flags you need for somelib:

pkg-config --cflags somelib

List what linker flags you need for somelib:

pkg-config --libs somelib

Then there's also --static if you're compiling statically.

pkg-config outputs in a format that is ready for gcc, so you can use backticks to run it and get the output when invoking gcc on the command line:

gcc program.c `pkg-config --cflags --libs zlib`

Or if you use a makefile you can capture it in variables:

LIBS := $(shell pkg-config --libs zlib)
CFLAGS := $(shell pkg-config --clfags zlib)

25Mar/130

Set Keyboard Repeat Delay and Rate

In order to change the key press repeat delay and rate we use a command called

xset

which is a user preference utility for X.

This command:

xset r rate DELAY RATE

where DELAY and RATE are replaced with actual values, in milliseconds. for example:

xset r rate 200 20

First, use

xset q

to see what the current values are. As shown above, I have mine set to 200 delay and 20 repeat rate.

To make this permanent, add that line to your ~/.xinitrc

xset can be used for a lot more than this. As always, use

man xset

to find out more about this command.

22Mar/130

Create Screenshots from Terminal Emulator

Probably the simplest way to create screenshots is using the commands

xwd

which dumps an image of an X window and

convert

which is a member of the ImageMagick suite of tools. It can be used for much more than converting image formats, but that's what we'll be using it for this time.

Screenshot of Whole Screen

So, to take a screenshot of your whole screen and call it capture.png, run this:

$ xwd -root | convert - capture.png

Add a Delay

Let's say you want to add a delay before the screenshot is taken (say, to move the terminal window out of the way), then simply add a sleep command before the others. For example:

$ sleep 3; xwd -root | convert - capture.png

adds a three second delay before the x window is dumped, and converted to a png.

Screenshot of Single Window

The "-root" argument to xwd tells it to capture the entire X window tree, the whole screen. If you leave it off, you will be given a cursor to click the window you want to capture.

So, if you just want to take a screenshot of a single window, then just run:

$ xwd | convert - capture.png

And click on the window you want.

Note:
I say "terminal emulator" because the xwd command relies on X to be running. This would not work on a login without X running.

18Mar/130

List Installed Packages in Debian or Ubuntu

In order to display the list of installed packages, use this command:

dpkg --get-selections

Chances are you have a lot of packages installed, so use grep to find something particular, for example, to see any packaged with the word "gnome" in their name:

dpkg --get-selections | grep gnome

Or, if you want to see how many packages you have installed, you can use the wc program:

dpkg --get-selections | wc

The first number is the number of lines dpkg output, and since there is one line per package, it is the number of packages installed.

11Mar/130

Git in Color

To enable color in git, simply use this command:

git config --global --add color.ui true

That adds the following lines to your .gitconfig:

[color]
        ui = true

There, now you'll see git's greens and reds, which make it much easier to see what's changed.

Don't worry, the color codes will only be used in interactive mode and not when piping output from git to other programs.

Tagged as: No Comments