Some Tricks of Using Terminal Console

Started by Donald Darden, November 22, 2007, 11:29:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Donald Darden

Dispite the presence and use of GUI interfaces on all prominent Linux distributions, the continuing use of a terminal console is assured.  Tes, many things can be done more easily and with less effort using the GUI menu, once you know your way around it, but the future of the terminal console is assured for one simple reason:  It's much easier and far more specific to explain a series of commands needed for performing some task than it would be to descrive the gestures and mouse clicks needed to do the same thing using the desktop menu, particularly since each distribution's menu is likely to be different.

Here is an example of what I mean,  I am going to quote portions of a topic that I found on the Internet, along with the text-based commands used to complete the task:
QuoteConverting .rpm Packages To Debian/Ubuntu .deb Format With Alien
Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
2 Alien Installation

Alien is available in the normal Debian repositories, so we can install it like this:

apt-get install alien

3 Converting .rpm To .deb

Next we download the current mysql-zrm rpm package (1.1-1 at the time of this writing):

cd /tmp

To convert it into a .deb package, we simply run

alien MySQL-zrm-1.1-1.noarch.rpm

Afterwards, run

ls -l

in the /tmp directory, and you'll see that alien has created the file mysql-zrm_1.1-2_all.deb. You'll also notice that alien has counted up the version number, it's now 1.1-2 instead of 1.1-1. If you want to keep the original version number, you must use the -k switch:

alien -k MySQL-zrm-1.1-1.noarch.rpm

will create the file mysql-zrm_1.1-1_all.deb.

To install the new .deb file, we use dpkg -i:

dpkg -i mysql-zrm_1.1-1_all.deb

Now mysql-zrm is installed and fully functional (you still might have to edit its configuration file though).

If you want to save the dpkg -i step, you can have alien install the package. The command

alien -i MySQL-zrm-1.1-1.noarch.rpm

would convert the original rpm package and immediately install it.

You see, converting .rpm files to .deb files is very easy. You can have a look at

man alien

to learn about what else you can do with alien. 

Each of the commands mentioned above has to be performed in a terminal console window.  In general, getting a terminal window open is really simple - there are probably several available under the GUI menu tags, one likely on the bottom and/or top taskbars, and using Ctrl+Alt with F1 through F4 will likely take you right to a command prompt.  So getting there is no big thing.  Exiting is also easy. as the terminal consoles can be closed by clicking on the big X in the upper right corner of the surrounding frame, or typing Ctrl+Z, or typing in the word exit and hitting Enter.

Now some commands can only be performed if you are logged in as the root or su (super user).  On some systems, you are not permitted to log in as root or super user when entering the GUI environment, so when you try and use one of the menu specified products, unless it asks for the necessary password, you will be prevented from performing the desired task.  Again, in these cases, the use of the terminal interface may be your best option.

If you enter the terminal mode and need to become root or super user, you have three ways to do this:  You can enter su, and if the system permits you, go ahead and log in as the super user.  Or you can enter sudo before each command where you have to have su level authorization, or sudo -s, which will let you become super user until you enter exit, your su mode times out, or close the terminal session.  You can also tell the system that you want to log in as another user, but that approach really isn't necessary in this case.

The next thing that you are then faced with is typing exactly all the long file names and commands that you sometimes encounter.  It's funny, but Linux developers insisted on keeping a lot of command names really short, like ls for list, or rm for remove, then they picked a longer syntax for any switches to use with those commands, like --verbose or --color=never. and then really got carried away with the idea of having really long descriptive file names, something like VMware-server-1.0.4-56528-i386.rpm, which is an actual file name.  Later, some of the switches were also provided in a shortened form, such as -v in place of --verbose, but packages for installing or updating software tend to be very detailed and lengthy to denote what they are and where they fit in the order of builds and releases.

So obviously it would be highly beneficial if you could avoid a lot of needless typing, right?  That means using cut-and-paste instead.  Now often, you want to cut and past from something found in a web page somewhere.  And generally, there are three ways to accomplish this.  The first step is to highlight the exact text that you want to cut and have moved to the clipboard automatically.  You can do this with the shift key and cursor keys, or shift key and hold down the left mouse button as you drag the mouse pointer over the desired text.  This is pretty much the same way as done under Windows.  The three ways of then actually doing the cut could be the use of the Ctrl-C, Ctrl-X, or shift-Del keys.  This often varies by the type of document or web page you are currently accessing, and the methods allowed by the document originator.  But none of these methods will work on the terminal console window itself.  There, what you have to do is use the menu taskbar and select under Edit that you want to do a copy.  You will likely note that there is no hot key combination listed for this important step.  The paste step is almost always the shift-insert key combination when pasting in the terminal console window, and has to be done on the command prompt line.

What you cut and paste can be interfaced with other information.  For instance, if you want to know if a certain package is installed. you can do a cut on the package name, type the command whereis on the command line, then paste the package name behind it.  Depending on how you performed the cut, you can leave off the end of line, which will allow you to edit the line before you press the Enter key and cause it to be executed.  Editing the line is simply a matter of using the cursor keys to move back and forth, judicious use of the delete or backspace key, and inserting new text.  No need to return to the end of line before pressing the Enter key either.

Note that whereas does not need to know all the particulars about a certain package before determining if it is installed.  For instance, if any version of wine is installed, just ask whereis wine, and any related executable files are listed with regards to the folders they occupy.

By knowing how to use cut and paste with regards to terminal sessions, you are in a much better position to implement the type of instructions you are likely to encounter online.  When a series of instrcutions are given, you can either cut and paste these one line at a time and execute them, or render them all into a script file that can be executed in a single step.  In general, I think doing them singly is better simply because you can see the result of each operation and gain a better understanding of what is going on.