Linux For Cynics One user's experiences with Linux

29Jan/140

bro pages: an improvement on man pages

bro pages are a highly readable supplement to man pages.
bro pages show concise, common-case examples for Unix commands.

6May/130

Simple Command Line Calendar

The cal program displays a simple calendar on the command line. Here are some examples of its use:

Invoking it with no arguments displays the current month.

$ cal

Output:

      May 2013        
Su Mo Tu We Th Fr Sa  
          1  2  3  4  
 5  6  7  8  9 10 11  
12 13 14 15 16 17 18  
19 20 21 22 23 24 25  
26 27 28 29 30 31

To see a particular month, run it with like cal month year:

$ cal 12 2013

Output:

   December 2013      
Su Mo Tu We Th Fr Sa  
 1  2  3  4  5  6  7  
 8  9 10 11 12 13 14  
15 16 17 18 19 20 21  
22 23 24 25 26 27 28  
29 30 31  

To see a whole year, run it with like cal year:

$ cal 2013

Or to display a 3 month period instead of just the current month, use the -3 flag:

$ cal -3

Output:

     March 2013            April 2013             May 2013        
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
                1  2      1  2  3  4  5  6            1  2  3  4  
 3  4  5  6  7  8  9   7  8  9 10 11 12 13   5  6  7  8  9 10 11  
10 11 12 13 14 15 16  14 15 16 17 18 19 20  12 13 14 15 16 17 18  
17 18 19 20 21 22 23  21 22 23 24 25 26 27  19 20 21 22 23 24 25  
24 25 26 27 28 29 30  28 29 30              26 27 28 29 30 31     
31         

This flags can be combined.

Finally, use the ncal command instead of cal to display the calendar in a more space-efficient way:

$ ncal 12 2013

Output:

    December 2013     
Su  1  8 15 22 29   
Mo  2  9 16 23 30   
Tu  3 10 17 24 31   
We  4 11 18 25      
Th  5 12 19 26      
Fr  6 13 20 27      
Sa  7 14 21 28 
Tagged as: No Comments
1May/130

Virtual Richard Stallman

vrms is a package that will analyze the set of currently-installed packages on a Debian-based system, and report all of the packages from the non-free and contrib trees which are currently installed.

Just run this command and you can find out what software you have on your system that doesn't respect your freedom!

$ vrms

Here's the output on my Debian laptop:

                Non-free packages installed on x200

firmware-iwlwifi                    Binary firmware for Intel PRO/Wireless 3945 and 802.11
skype                               Wherever you are, wherever they are

                Contrib packages installed on x200

flashplugin-nonfree                 Adobe Flash Player - browser plugin

  2 non-free packages, 0.2% of 1164 installed packages.
  1 contrib packages, 0.1% of 1164 installed packages.

It's like having a little rms right on your command line!

To find out more about Richard Stallman and his political views, go to his personal page: stallman.org.

29Apr/131

Wifi from Command Line

In this short how-to I'll show you how to connect to a WPA wifi network from the network without any GUI tools.

First, we have to install the relevant software. Some distros do not come with much wifi firmware or wpa support out of the box and they must be installed after the fact. In Debian, follow this guide to install them.

Display the currently active network interfaces:

$ sudo iwconfig

You should see something like wlan0. Let's activate it:

$ sudo ifconfig wlan0 up

Optional if you know the SSID of the network you want:
Scan the interface for access points:

$ sudo iwlist wlan0 scan

Open the /etc/network/interfaces file (replace editor with text editor of your choice):

$ sudo editor /etc/network/interfaces

and add an entry for the network you want to join (replace words in CAPS with your details, where NAME is what you want to call the entry):

iface NAME inet dhcp
  wpa-ssid YOUR-SSID
  wpa-psk YOUR-PASSWORD

Now, just connect to that network!

$ ifup wlan0=NAME

To connect to a different network, simply add another entry to /etc/network/interfaces and run ifup wlan0=NEW-NETWORK-NAME.

24Apr/130

Install Wifi Firmware and WPA Support in Debian

Debian is a wonderful distribution but it is a bit strict on what it comes packaged with. Most wifi cards do not have open drivers, so you have to install them from the non-free repos. Here's now to install them and use them with wpa-supplicant.

First, we need to add the non-free Debian repositories. Add these lines to the /etc/apt/sources.list file:

deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
 
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

Once the non-free repo is added, update and install the driver I need. You might need different firmware:

$ sudo apt-get update
$ sudo apt-get install firmware-iwlwifi

Also get the wireless-tools package:

$ sudo apt-get install wireless-tools

So we have the driver, but now we need to use it!

Since the iwlwifi module is automatically loaded for supported devices, we need to reload this module to access installed firmware:

$ sudo modprobe -r iwlwifi ; modprobe iwlwifi

Now we see if the device has an available interface:

$ sudo iwconfig

Yep! Mine is called wlan0. Connecting to a wpa secured wifi will be covered in the next post.

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.

15Mar/139

Minimal Debian Install

Here's my guide to installing a lean Debian desktop. I went through these steps on a Thinkpad X200. Your needs may vary. Skip the parts that don't apply to you. This post will get you from zero to a working desktop. I will cover additional configuration and customization in another post.

Debian Net Install

First, get the net installer here: Debian Install Images. I went with the current Testing version, Wheezy. It should be suitable for most desktop users.

Because this is a net install, make sure you have an ethernet connection. Wireless won't do.

I'm assuming intermediate level experience with Linux in this guide so I won't go through each step of the installation. I'll leave paritioning and all that to you.

Once you get to the "Select and install software" step, select only SSH Server, Laptop Tools, and System Utilities.

Install sudo

If you did not supply a root password, sudo is already set up and you can skip this step. If you did provide a root password, you need to do it yourself. Time to install sudo and add yourself to the sudo group. This is not strictly necessary, but there are many benefits to using sudo over su. Let's say your username is dave.

$ su
# apt-get install sudo
# adduser dave sudo
# exit

Log out and back in again and there we go!

Wireless

This isn't necessary if you don't have a wireless card, naturally.

As for me, this is a laptop, so I need to install wifi drivers. I installed using an ethernet cord but that won't do in the long run.

First, we need to add the non-free Debian repositories. Add these lines to the /etc/apt/sources.list file:

deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
 
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

I wanted to use vim to do so, but it wasn't added. So, I installed vim:

$ sudo apt-get install vim

Once the non-free repo is added, update and install the driver I need. You might need different firmware:

$ sudo apt-get update
$ sudo apt-get install firmware-iwlwifi

Also get the wireless-tools package:

$ sudo apt-get install wireless-tools

So we have the driver, but now we need to use it!

Since the iwlwifi module is automatically loaded for supported devices, we need to reload this module to access installed firmware:

$ sudo modprobe -r iwlwifi ; modprobe iwlwifi

Now we see if the device has an available interface:

$ sudo iwconfig

Yep! Mine is called wlan0

Configuring your wifi can be done now through the terminal using wpa-supplicant, or you can wait until we have a GUI. I'm going to show you how to use wpa-supplicant because it's harder.

Time to use wpa-supplicant (installed with wireless-tools) to connect to my wireless network. Let's setup wlan0 with the SSID and PSK. Edit /etc/network/interfaces and add these lines:

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid YOUR-SSID-HERE
    wpa-psk YOUR-PASSWORD-HERE

Now let's see if it worked.

$ sudo ifup wlan0
$ sudo ifconfig wlan0
$ ping router-ip-here
$ ping google.com

Yep! all good.

Desktop

Okay so installing X is very easy:

$ sudo apt-get install xorg

We could startx now, but that would just give us an xterm. So let's choose a window manager. I'm avoiding full-blown Desktop Environments (such as GNOME or KDE) because this is supposed to be a light-weight install.

My favorite tiling WM is dwm, and my favorite floater is Openbox. I think I'll install them both, as sometimes things work in Openbox and not in dwm (such as screen sharing in Google Hangouts...I dont know why).

First the easy one, Openbox:

$ sudo apt-get install openbox

Because the scripts in /etc/X11/Xsession.d will eventually run x-window-manager, which is presumably set to openbox via the alternatives mechanism (/usr/sbin/update-alternatives --display x-window-manager), at this point you could type

$ startx

And start using Openbox right away, but I'm going to focus on dwm since it's my favorite.

Install your favorite window manager or desktop environment. I like dwm. But, because dwm is configured by modifying the source code and recompiling, it is best not to install it through the repositories (although that is an option if you don't care to change the defaults). The best way to use dwm is by using git, modifying the source, and compiling it yourself. Here's a guide. It can be summarized as the following:

Installing dwm "properly" means downloading the source, modifying it to our liking, and compiling it. This is because dwm doesn't use configuration files or scripts to customize it, the source itself must be changed.

So that means we'll need gcc, et al. If you're a programmer you'd get these things anyway:

$ sudo apt-get install build-essential

dwm requires x11 development libraries, as well as Xinerama development libs (if you want dwm to support mult-monitor). So install those too:

$ sudo apt-get install libx11-dev libxinerama-dev

Now let's get the dwm source code. I'm gonna use git.

$ sudo apt-get install git

And get the source from the suckless git repo:

$ git clone http://git.suckless.org/dwm

That will create a directory called dwm.

$ cd dwm

Now make a copy of the config.def.h file so your configuration doesn't get clobbered if you download the source again:

$ cp config.def.h config.h

Make any changes you want to config.h. I won't go into it here.
And finally, compile and install dwm!

$ make clean install

In order to use dwm, we need to make startx use it. So let's create and modify our ~/.xinitrc

$ vim ~/.xinitrc

And add this line to the end of it:

exec dwm

Done!

Now just run:

$ startx

minimal_dwm

Now we have a desktop.

Sound

Let's install alsa.

$ sudo apt-get install alsa-base alsa-utils

And get it started:

$ alsactl init

And now test it to see if we can actually hear anything:

$ aplay /usr/share/sounds/alsa/*

Should hear a woman's voice saying "Front center" etc.

Something else you might start hearing is an annoying beep. This is called the PC bell. Disable that damned PC bell.