Showing posts with label CLI. Show all posts
Showing posts with label CLI. Show all posts

Uncompress files using CLI

I usually uncompress all kinds of packaged files from the command line. Unfortunately, I rarely remember which command line tool I should use for some specific packaging format. It is even more difficult to remember all the options needed for the appropriate tool.

Now that I found a cool hack in the ArchWiki, I never need to look for more information about how to uncompress a .tbz2, .tgz or .bz2 file -- I just use extract filename.

Add the following snippet of code to your .bashrc and you are ready to extract any file (if your system has the corresponding tool installed).


extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvJf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*.xz) unxz $1 ;;
*.exe) cabextract $1 ;;
*) echo "\`$1': unrecognized file compression" ;;
esac
else
echo "\`$1' is not a valid file"
fi
}

Wordgrinder -- Word Processor for the Linux Console

One of the few things I miss from the years when I used MS-DOS is WordPerfect 5.1. It was a perfect application for writing and few WYSIWYG word processors if any have been as userfriendly as WP was. For the last seven or eight years I've been constantly looking for a perfect word processor. I have used KWord, Abiword, OpenOffice, LyX and even Emacs for writing. Sometimes, I have planned to install a copy of WordPerfect under FreeDOS just to recreate the simple desktop with no distractions like Firefox. But there were, of course, things like Tetris and Civilization that sometimes kept me from writing for days.



Today I decided to test yet another Linux word processor -- WordGrinder is probably the one and only console mode word processor that exists for Linux. It is as simple as it gets, but not too simple. WordGrinder uses a binary format for its files, which makes them unreadable for ordinary text editors. It can, however, export the files to plain text and html. The latest version (0.3) should even export the text to LaTeX and troff for the geekiest users. Unfortunately, my Debian still has the version 0.2 that does not support all of the fancy stuff mentioned in the web site for WordGrinder.

Rip CDs on the command line: ripit

I try to use simple command line tools for many tasks that most readers probably accomplish with the default tools provided by GNOME or KDE. Thus I like to listen to the ogg vorbis music files using ogg123 and I rip my CDs using ripit.

Ripit is a command line tool written in Perl. It is a front-end to several other command line tools and provides them an easy to use interface that is as simple as it can be. It can fetch the CD title and track information from CDDB, rip the CD, tag the songs, create a playlist and edit the CDDB information, if necessary. Usually I just accept the defaults provided by the application.

Simple and effective.

dc - A Text Mode Calculator

A few weeks ago, I wrote about bc. It can be used as a simple arbitrary precision calculator text mode and for executing mathematical programs written in bc programming language.

Today I noticed that I have yet another simple text mode calculator installed in my desktop system: dc. It is similar to bc but differs from its cousin as dc uses reverse Polish notation instead of normal mathematical notation.

For example, to add two numbers in dc you first push the numbers into stack, then enter the aritmetic operation which pops the numbers out of stack, adds them and pushes the result in stack. Finally p prints the result:

10 2.2 + p
12.2


More information about dc is provided, as usual, by info dc and man dc.

dc is a real oldie in the GNU - it predates even the C programming language. Learning dc is a way to travel back in time to an era when nobody thought computers and operating systems should be user friendly.

You should at least give dc a try, as you can always jump back to the present and continue using GNOME calculator or OpenOffice.Org calc if you really want to!

Text Mode Linux Applications

During the first year of blogging for Lightweight Linux, I have written about many useful text mode applications. Some of them might be considered obsolete by modern standards, but they might well be enough to satisfy the needs of a command line junkie.

Here is a short overview of the applications I have written about.


  1. Twyt is a command line Twitter client. It is a lot more sophisticated than my own simple three-line Twitter script that can only update the status.
  2. e3 is a very lightweight text mode editor that can emulate the keyboard shortcuts of several better known editors like Emacs and vi.
  3. wtf deciphers acronyms.
  4. Adventure is an old text mode adventure game - a classic early example of interactive fiction.
  5. Nethack is another golden oldie. It is even installed on some of the proprietary Unix systems at the University where I used to study.
  6. Alpine is a simple and easy to use email client. The article shows also how to configure it to for gmail.
  7. If you are looking for a text mode contact manager, take a look at abook.
  8. Midnight commander, a.k.a. mc is a text mode file manager.
  9. Burn your CDs and DVDs with cdw.
  10. Create postscript calendars on the command line with pcal.
  11. Text mode reminders can be handled by remind .
  12. Catdoc and antiword are useful for reading Microsoft office formats.
  13. What about reading pdf files in text mode? No problem!
  14. Htop is better than top.
  15. I use wget for downloads.
  16. One can even browse the net with some of the text mode web browsers.
  17. And finally, bc is a command line calculator.

Any suggestions for future articles? What are your favourite text mode Linux applications?

bc is a command line calculator

Very often I need a simple command line calculator to do some simple math for my accounting or economics classes. Usually I don't need anything more complicated than the simple arbitrary precision calculator bc. The bc is very intuitive to use, after you learn to set the precision used in calculations:

scale=5

This sets the precision to five digits. Unless you define the precision bc will default to integer results which would not provide especially precise results. After setting the precision, bc is very intuitive to use. For example:

mjp@oikos:~$ bc
bc 1.06.94
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale=5
10/3
3.33333

A lot more information can be found with man bc, as usual.

twyt for CLI tweets

For a couple of days, I thought I would write some more scripts for using Twitter on command line. After some googling, I discovered there was already a command line twitter client available that would completely satisfy my needs.

Twyt is available as a source package from Andrew Price's home page. Download first the tar.gz package from the download page and unpack it with tar -xvf twyt-0.2.2.tar.gz. Install the package with ./setup.py install.

Twyt is written in Python, so you need to have Python installed, as well. In addition, twyt depends on the python-simplejson. I was able to install it directly from the Ubuntu repositories.

Next, create your Twitter user with:

twyt user -u username -p password

After this, you can tweet with

twyt tweet "#twyt is a nice command line twitter client"

You can read the updates by friends with:

twyt friendstl

More information is provided, of course, by man twyt.

Twitter updates from Linux CLI

During the last week, I've learned to use Twitter. Of course, there is not a lot to learn as Twitter is a really simple system. Consequently, it can easily be updated from the Linux command line without using any dedicated application or a bloated web browser. You just need to have curl installed on the system to use the following command:

curl -u "username:password" -d "status=here comes the status update" http://www.twitter.com/statuses/update.xml

And to make it even simpler, you can write a simple script to send the updates from the command line:

#!/bin/bash
echo "Twitter update: $1"
curl -u "username:password" -d "status=$1" http://www.twitter.com/statuses/update.xml >/dev/null


After saving the script as tw I made it executable. Now I can send updates with:
tw "This is my update"

If you intend to send a lot of tweets from the command line, you should probably add some sanity checks to the script.

Edit: I added >/dev/null to the end of the third line in the script in order to reduce the amount of text output.

e3 is an editor with many faces

A few days ago, I learned about a lighweight console editor I had never used before. E3 is a very small and lightweight editor that can emulate the most important keyboard shortcuts used by VI, Emacs, Pico, Nedit and even Wordstar.

I think I haven't used Wordstar since 1980's and I doubt there are many geeks around who still want to use Wordstar's keyboard combinations. I would rather have an editor that emulates WordPerfect 5.1 but I suppose that running WordPerfect in Dosemu is the only way to get a decent console mode word processor.

In case you are not looking for a console word processor but a simple text editor to quickly edit a few configuration files or maybe a LaTeX source you might find that e3 provides everything you need.

wtf is wtf?

I happened to install last week - quite accidentally - a cool little command line tool I want to share with you today. As I installed the package bsdgames in my antiX box I got quite a few text mode games installed. In addition to the games, wtf was installed in my system.

I'm not quite sure if wtf really is a game. It is a small tool that searches for acronyms and their explanations in a dictionary file. And in case you don't know what the acronym wtf stands for, you can let the tool explain it's name with the command:

wtf is wtf

Now that I have this tool installed in my system, I don't have to remember and google for AFAICR, AYT, CMIIW, FIGJAM and other completely unintelligible acronyms I encounter while reading discussions on different Internet forums.

Adventure in text mode

My first computer was a Commodore 64, that was one of the most popular home computers in the 1980's. I used the computer mostly for games and learning to code, first in BASIC and later in 6510 assembler. As the screen resolution for multicolored graphics was only 160x200, I often played text mode adventure games. To be honest, the 40x25 text mode screen was not very pleasant, either.

Text mode adventure games were a popular genre in the 1980's but nowadays it seems a dead genre. The young people are more accustomed to playing 3d adventures than trying to guess the right verb to use in a two-word sentence to command the hero to some simple action. The early adventures used only literary descriptions of places and problems encountered had to be solved by giving commands like take bottle, enter building, use key, open door etc.


If you are ready to go back in time to the 1970's and 1980's, you might like to try the adventure. In Ubuntu, it is provided by the package bsdgames.

Nethack is the game for geeks

Around 15 years ago I played for the first time Nethack. I should have been working on my MA thesis in medieval ecclesiastical history but I probably spent a lot more time online: reading the newsgroups, chatting in the IRC or in the university's internal bulleting board known as Portacom.

Sometimes I even played games on the Unix system. There were not too many games installed, but there were many online multiuser dungeon games I was able to play over telnet. And the famous Adventure was available and of course the Nethack.

I was never completely hooked on Nethack, but I completely understand those geeks who spent the nights hacking monsters in the darkness of the dungeons. Sometimes I have even tried to play Nethack with my Linux systems. It certainly is not for everyone, but it is one of the few playable games available for the Linux console.



Even if you might not fully understand the magic of Nethack it is certainly worth installing in the Linux system. If you are desperate enough you might even like to start killing the monsters in the deep dungeons!

Alpine is a great text mode email application

I have used pine as my main email application since 1993 and I'm not even considering to replace pine with a more modern email application as long as pine is available in the Unix system where I read my email. When I need to read email that has been sent to some of my private email accounts
(like the one I use for this blog) I most often use alpine installed on my Linux box.

Alpine is a rewrite of the original pine. Unlike pine it uses an Apache license that allows redistribution of modified versions of the application which makes it more acceptable for free software enthusiasts.



Alpine uses a simple menu interface for composing and viewing email messges. For writing a mail, it uses the extremely newbie friendly editor pico that can of course be used also as a standalone editor for editing any text files you might like to edit. From the main menu of Alpine one can enter the simple to use setup dialogues, where one can set many options including the signature, printer, non-default address books, rules for automativally filtering the messages in different folders, set the screen colors, and a lot more.

Most probably you receive your email not directly in your box but instead use a mail account provided by your ISP or for example Google. In fact, it is quite simple to configure Alpine to read and send email using a Gmail account like I have done for reading the lwlinux account I use for receiving mail about this blog.

If you want to use Alpine with Gmail, go first to the setup menu. Then select Config. In the next screenshot you will see how the settings for Gmail are done, only a few lines must be configured.



If you have never used a text mode email application you should at least give alpine a chance. It is easy to use and configure and a lot easier to use than most of the graphical email applications. You will soon realize how easy it is to read and write emails when you don't have to move your hand all the time between the keyboard and the mouse.

See also my previous articles about text mode Linux applications:
Burn CDs and DVDs with cdw | Remind is a lightweight tool for reminders | Lightest WWW browsers for Linux | Manage your contacts with abook

Manage your contacts with abook

I'm constantly looking for applications that can comfortably be used even with an old computer. Some days ago, I posted an article about lightweight personal organizer OSMO. Now I have found something even more lightweight!

My new address book manager is abook. It is a simple text mode organizer for storing contact information. It has a simple to use user interface (using ncurses) and does not force the users to remember obscure CTRL sequences or vi-like keyboard shortcuts. On the contrary, the keyboard shortcuts are few and they can be seen on the top of the screen.

Abook utilizes a simple card view for the contacts. The contact information is divided on five tabs where address, phone, other information and custom information have been dedicated a tab. Abook can be used as a standalone application or it can be used as the addressbook for mutt email application.



It is possible to import and export contact information using the command line option --convert. Abook can convert the the contact information from the following formats:
  • ldif
  • mutt
  • pine
  • csv
  • palmcsv

The following output formats are supported:
  • abook
  • ldif
  • mutt
  • html
  • pine
  • gcrd
  • csv
  • palmcsv
  • elm
  • text
  • spruce
  • wl
All the contacts are of course stored in a plain text file (default: ~/.abook/addressbook) that has an easy to understand format.

Manage your files with mc (Midnight Commander)

Once upon a time, there was a operating system called MS-DOS. It was a pretty limited system and awkard to use, but at the same time, it was a lot more useful than the graphical systems built on the DOS. To help the users, many companies created proprietary software that was sold to the end-users.

One of the most popular applications was Norton Commander or simply nc. The first version 1.0 was released as early as in 1986 [1]. This application set the standards for file managers for a long time. In fact, many file managers even today follow the concept of showing files simultaneously in two panels.

In addition to GUI file managers, the command line junkies can use the Midnight Commander, mc. It is available for probably every possible distribution in use. If you like to use Linux on an old computer, you might well try this application that does not steal all the resources of your old computer.



Midnight Commander provides all the usual functionality one expects from a file manager. With it, it is possible to copy, delete, archive, view and edit files or, for example, view man pages, It might not handle everything konqueror handles, but it does well what it is intended to do.

See also: Burn CDs and DVDs with cdw | Remind is a lightweight tool for reminders | Lightest WWW browsers for Linux

Burn CDs and DVDs with cdw

There are several useful applications available for burning CDs and DVDs on a Linux system. The geekiest users are probably happy with command line tools while most users are happy with k3b or gnomebaker.

Cdw is a ncurses based alternative to more famous tools. As a ncurses application it can be used on system with no X installed but as it has a menu based user interface it might be easier to use than the command line tools. In fact, cdw is just a frontend for cdrecord/wodim (for blanking CD-RW discs, writing data to single- or multi-session CD disc and single-session DVD discs) and mkisofs/genisoimage (for creating ISO images from selected files).



If you -- like me -- have difficulties in remembering the options of different CLI tools, you might like to try this small application. It is available at least in the repositories of Ubuntu and Debian testing (but not yet in the stable release).

If it is not included in your distribution's repositories, you can always get the source from the Sourceforge.

See also previous articles on text mode applications!

How to Print PostScript Calendars from Linux Console

There are so many command line tools for printing calendars and calculating dates, weekdays, lunar cycles, easter dates and lot more that it is difficult to remember all the possibilities these tools have to offer. I suppose everyone knows that the commad date prints the current time and date, and some probably most of my readers know how to print the calendar of current month using cal, gcal or ccal.

These tools are capable of lot more than simply outputting the current calendar to the standard output. Just see info gcal and you certainly will learn a lot more about gcal you can remember! I wanted, however, simply get a postscript or pdf calendar to be able to print it and have it on my wall. It took me some time before I realized, that gcal was not, after all, the right tool for the job.



What I needed was pcal. Simple command pcal > calendar.ps did exactly what I wanted: it produced a file with postscript code needed for printing this month's calendar. pcal is of course capable of doing a lot more, man pcal for more information.

Documentation for CLI Newbies

This time I would like to recommend a great source of information for all my readers who like to use CLI applications on their lightweight Linux installations. As I have pointed out earlier, if you try to use Linux on a very old computer, you have to use some of your own brain power to compensate for the lack of a fast CPU and lots of RAM.

Gareth Anderson has written an useful summary of command line GNU/Linux applications. It is organized thematically, so that you can easily find the most useful tools for e.g. controlling processes and services, manipulating text files or working with the file system.

Michael Stutz's The Linux Cookbook: Tips and Techniques for Everyday Use is another good source of information with similar topics. It is a bit old (written in 2001), but the CLI tools don't change as fast as KDE and GNOME applications!

Both of the ebooks are highly recommended reading for all Linux newbies who are not afraid of command line!

Remind is a lightweight tool for reminders

I like to use lightweight tools whenever possible as there is no point in running IceWM if one uses KDE or GNOME applications for everyday tasks. Because my memory is far from perfect, I like my computer to remind me about the projects I have to work on and about classes I have to attend.

There are some obvious choices for this kind of task if one uses KDE or GNOME. For exapmle, Korganizer would be great tool for keeping your calendar and to do lists. I decided to use a command line tool, remind, for storing all the information about my meetings, classes, and deadlines.

Remind uses a plain text file for storing information. The syntax for ordinary reminders is pretty simple and evident, as you can see from a few lines of my .reminders:

REM 22 September AT 16:00 YLY Mercatori
REM Tue AT 08:30 YLY/MENY1
REM Tue AT 11:15 TKMY1_ls17
REM Tue AT 14:15 RuIb1

These are reminders for a meeting on the 22nd of September at 16:00 and three reminders for my classes on tuesdays. It is possible to use much more sophisticated reminders that have rules for deciding the date of some action. You can also set the remind to warn you in advance, before the actual date of the reminder, but I like to keep my reminders simple.

I like to use remind for printing a schedule for the next week every sunday. As I have stored my reminders in the file .reminders this can be done easily with a simple command: rem -c+1



If a weekly calendar is not enough for you, you might consider printing out a PostScript calendar of your reminders for the next twelve months with remind -p12 .reminders |rem2ps >remind.ps.




There are many good sites about using remind in an efficient way. Let your computer remind you of your meetings, classes and deadlines. It will help you to get things done!

[1] Manage your time with Remind
[2] Remind: The Ultimate Personal Calendar
[3] 43 Folders' wiki

HOWTO Read rtf Files in Linux Console

Today I continue where I finished yesterday. I have so far written about reading doc and pdf files in Linux command line. Today I turn to rich text format, that is the files with extension rtf. Rtf is a very common format used by those who are at least slightly familiar with the compatibility problems caused by using Word's binary file format. Also rtf can be viewed using lightweight tools, it is not necessary to use OpenOffice.org to read the file.

I was reminded by my reader Reidar about catdoc, yet another Linux tool for reading windows file formats. As I don't have MS Word installed on any of my computers, I used Abiword for writing a short text (in fact this blog posting!) and saved it as a rich text file. And I was not disappointed by catdoc. It printed the content of my file on screen just like cat would do with an ordinary plain text file. You might be able to find it in the repositories of your distribution.

Catdoc is a tool that doesn't attempt to analyze and reproduce file formatting. It just extracts readable text from the file. What it can do, is to handle all versions of Word and convert character encodings. It can also read RTF files and convert Excel and PowerPoint files. You should install it in any system running on an old computer.



I thought that there are no console editors that can edit rich text files. I was not even sure whether it such editors would make any sense. But as I knew that Emacs can do everything one might some day need to do with her computer, I decided to google for "Emacs rtf". Surprisingly, or maybe not, there actually is an Emacs extension for editing rich text files and VIM should be able to edit rtf files out of the box. We are living in a strange world, aren't we?