Howto Open a PDF file under Linux / FreeBSD

in Categories , , , , , , last updated March 26, 2008

PDF is an acronym for Portable Document Format. It is a proprietary file format developed by Adobe Systems for representing two-dimensional documents in a device independent and resolution independent format. You can open pdf file using graphical as well as command line tools (i.e. without GUI). Linux supports following PDF viewer under X window:

  • Gnome pdf viewer (gpdf)
  • KDE pdf viewer (kpdf)
  • xpdf
  • Official Adobe acrobat reader

Graphic pdf viewer under Linux/FreeBSD

If you are using Gnome desktop…

Open a shell prompt and type the command:
$ gpdf file.pdf
OR
$ evince file.pdf

If you are using KDE desktop…

Open a shell prompt and type the command:
$ kpdf file.pdf

You can also click on K icon > Select Graphics > Select PDF viewer

Console pdf viewer under Linux/FreeBSD

Console pdf viewer

As far as I know there is no console based PDF viewer exists. But you can use the following trick to open a PDF file:

a) First install pdftohtml – A command-line tool for converting pdf-files into html and other formats.

Debian User install pdftohtml using following command:
# apt-get install pdftohtml
Red Hat / Fedora user install pdftohtml using following command:
# yum install pdftohtml
FreeBSD user install pdftohtml using following command:
# pkg_add -v -r pdftohtml
OR use ports collection:
# cd /usr/ports/textproc/pdftohtml
# make; make install

The idea is very simple you will use a pdftohtml program to convert a PDF file into html, xml and png images and then display them using text browser such as elinks or lynx. This is useful when you works on remote server or if GUI is not available:
For example to convert CH09.PDF file you need to type the following set of commands:
$ pdftohtml CH09.PDF
$ lynx CH09.html

OR
$ elinks CH09.html

You can also convert a PDF file to text file using following command:
$ pdftotext CH09.pdf
$ vi CH09.txt

See also

=> You can get Official Adobe acrobat reader here for UNIX/Linux oses.

Linux how do I remove all empty directories?

in Categories , , , , , , , , last updated February 2, 2007

You can use program called cleanlinks. The cleanlinks program searches the directory tree descended from the current directory for symbolic links whose targets do not exist, and removes them. It then removes all empty directories in that directory tree. It was originally created for symbolic links based directories but works with normal directories too.

For example if you want to remove all empty directories from /tmp directory, type the command:
$ cd /tmp
$ cleanlinks

Please note that cleanlinks command is part of XFree86 project. Another method is to use combination of shell commands in script:

#/bin/bash
DIR="$1"
 [ -d $DIR ] && [ $(ls -l $DIR | wc -l) -eq 1  ] && rmdir $DIR ||  :

Save and execute a script:
$ script.sh dir1

You can also try out tmpreaper command which recursively searches for and removes files and empty directories which haven’t been accessed for a given number of seconds. Normally, it’s used to clean up directories which are used for temporary holding space, such as “/tmp”. Syntax is as follows:
tmpreaper TIME-FORMAT DIRS

Where,

  • TIME-FORMAT : Defines the age threshold for removing files. The TIME-FORMAT should be a number, defaulting to hours, optionally suffixed by one character: d for days, h for hours, m for minutes, or s for seconds.
  • DIRS : Directory name for example /tmp

For example, remove all files accessed 24h before:

# tmpreaper 24h /tmp

Please note that tmpreaper command is not installed by default you may need to install it using apt-get or rpm command.

Howto: Linux desktop adjust sound or Linux volume control

in Categories , , , , last updated December 27, 2006

Q. How do I adjust Linux volume control?

A. You need to use a program called aumix to adjust sound / volume control. This program adjusts the settings of an audio mixing device. It can be used from the command line, in scripts, or interactively with the keyboard or mouse.

You can launch volume control as follows:
=> Click on Main Menu

=> Select Sound & Video

=> Now select Volume Control

aumix – command line program

Just type following command at shell prompt (open x terminal):
$ aumix
Output:

You can use following keys to control aumix sound settings:

  • page up, page down, up and down cursor: Select a new control.
  • Tab, Enter, , comma and period : Toggle between level and balance controls
  • + and – : Adjust the setting of the current device. The + and right cursor keys increase the level by 3%; the – and left cursor keys decrease it by the same amount.
  • S or s : Save settings to the rc file
  • U or u : Undo any muting
  • M or m : Mute or unmute
  • Q or q : End the program (exit to shell prompt)

Howto: Eject cd with ssh

in Categories , , , , last updated January 12, 2007

Eject allows removable media (typically a CD-ROM, floppy disk, tape, or JAZ or ZIP disk) to be ejected under software control. The command can also control some multi-disc CD-ROM changers, the auto-eject feature supported by some devices, and close the disc tray of some CD-ROM drives. Eject can be used remotely over ssh session to eject cds.

First login to remote system over ssh session:
$ ssh user@ras.nixcraft.in
Eject cd using device name:
# eject /dev/cdrom
OR Eject cd using mount point
# eject /mnt/cdrom/

To close tray type command:
# eject -t /mnt/cdrom/If you have multi-disc changer then you can use eject to select disc. For example, select 4th disc on multi-disc changer:# eject -v -c4 /dev/cdrom