Your friend, the alias. Part 1

First a little history.

A short while ago, someone in the PCLinuxOS forum was asking about apps that would allow mounting an ISO image to his desktop. I've used such apps in the past, but recent installations, using the latest version of my favorite one, (of the two I've used) MountISO, on newer distro versions throws up errors that the ISO image is not really an ISO image, or that it is corrupt. The problem seems to be that the latest version is from Oct. 16, 2005 and needs updating.

The other is a GUI app, AcetoneISO, which will mount various proprietary Windows burner image formats, as well. It works fairly well, but requires a multitude of other packages to work.(1) This is all fine and good, if one needs that functionality. However, I do not run Windows, so my only exposure to image files of a Windows type might be from an occasional download. For those occasional, odd files, I still use AcetoneISO, but I find AcetoneISO to be a rather clumsy way to mount the ISO images I do work with daily. Each mount requires a root password, and a directory choice, as to where the image will be mounted. This gets old rather fast, when one does this many times a day, so I created some aliases to do the job for me, without the hassles.

I suggested using this approach, as an alternative to AcetoneISO, in the forum thread, with instructions on how to do so. KDulcimer, one of the forum regulars, suggested that this might make a good article for PCLinuxOS mag. In further conversation, I wrote:

"I can type 4 letters faster than I can right click the image and navigate through three layers of menus.

When file browsing with Konqueror, I usually have the terminal emulator window open, which syncs with the navigation, and have, at present 72 aliases for the things I most commonly do. The longest alias is only 6 letters, most are 4, a few are only 3. Some of the aliases are for chains of other aliases that would otherwise require a long script, more complicated than I would know how to write. For instance, I download an item from Usenet binaries that is in split rar files, with par2 volumes for error correction. Both the unrar and par2 apps are command line only, and scare off a lot of users. By creating an alias for each process, and chaining them with other aliases, a single 5 letter entry, at the prompt, runs the par2 integrity test, makes the repair if it is needed, unpacks the rar volumes, and cleans up the directory so that only the unpacked item remains. I don't have to remember the various commands, arguments, and syntax, for each app, only the alias. If I forget the correct alias for the process I want, typing "alias" gives me the entire list, to remind me."

KDulcimer, responded with:

"Wow. Would you instead consider writing an article about aliases, how to create them, potential purposes, etc? This sounds like neat stuff."

I had already decided that would be the direction to take: Not one article, but a series of articles that would each be a "How to achieve a desired outcome using aliases." So as not to overwhelm the newbies, I will take one desired outcome, or a few related and intertwined outcomes, per article, and explain in detail why an alias would be desired, and then the process of creating it, or them. I will create a step by step set of directions, which the reader can implement, while they read the article.

There are already plenty of sources for this information, but most use boring examples, appropriate for programmers only, whereby most newbies go "deer in the headlights" when reading, and miss the entire point about the usefulness and simplicity of the process. They end up with even more fear of the command line than they started with. I hope that, by presenting the information in a real world context, with a subject they can directly relate to, explained in language that a normal child can follow, the process will be demystified, and the fear dispelled.

Borrowing heavily from the forum article, as I already wrote that in much the same manner as I intend to follow throughout the series, it would seem appropriate that the first should be:

"How to mount an ISO image on your desktop, as a normal user, using an alias,"

Rules and Definitions:

I will assume the reader is using the KDE desktop, and give directions based on that. (For those using Gnome, you will have to find any Gnome equivalents, if necessary, or use the KDE tools, where there are no equivalents.)

If I write something as <something> it means that the reader should substitute the item indicated with that which is appropriate to him. (I refuse to follow the "politically correct" him/her/self stuff when I write. Get over it, life's too short.)

When I say "open kwrite" for editing, if you like something else, substitute that and use what you're comfortable with.

Alt+F2 = Press the Alt, and F2 keys at the same time.

<Enter> = Press the Enter key

****** = Root's password

~/ = Your home directory

./ = This directory = PWD = Present Working Directory = The directory which you are now in, that contains the file you wish action upon.

* = Anything, Whatever = As used here, in the form, *.iso = Any file, by whatever name, that ends with the extension .iso.

FYI: = For Your Information. I will use this to explain what a command, or a file entry, does, or means.

Instructions:

First set yourself up as a sudoer. Alt+F2 brings up the "Run Command" box. In the box, type:

kdesu kwrite /etc/sudoers <Enter>

FYI: This asks the system to open the file "/etc/sudoers" with kwrite, with the root permissions needed to write to that file. Another box will open requesting the root password. Enter it.

****** <Enter>

Read the file, ignore the part that says it MUST be edited with visudo, and in the appropriate section, at the bottom, write:

<yourusername> ALL=(ALL) NOPASSWD: ALL

where you use your own user name in the obvious place. Save the file, and close kwrite. <--This is a little confusing...be more specific where to put the username information--”at the bottom” is a little vague.

FYI: You are now a sudoer, and will not be asked for a root password each time your alias uses sudo to mount, or unmount, an ISO image.

Next, create an empty directory on your desktop named "iso", without the quotes. Left click your "home" icon, and from the "View" menu select "Show Hidden Files". Open the file .bashrc with kwrite, and copy/paste into it, this line:

test -s ~/.alias && . ~/.alias || true

Save .bashrc, and close kwrite.

FYI: This tells bash, your shell, to test for the presence of a hidden file named .alias, in your home folder, and, if it's present, use it's contents as if it were an integral part of .bashrc.

FYI: The command to mount an ISO image is:

mount -o loop /path/to/<filename>.iso /path/to/<mountpoint>

where <filename> represents the actual name of the .iso file, and <mountpoint> is a directory name. Only root can use the mount command, hence the use of sudo.

Next, open kwrite, again, to create a new text file, and copy/paste these lines:

alias imnt='sudo mount -o loop ./*.iso ~/Desktop/iso'
alias umnt='sudo umount ~/Desktop/iso'

and save the file as ~/.alias.

FYI: The name of the file is ".alias" (without the quotes) and it is saved in /home/<yourusername>

FYI: I chose "imnt" as a unique, short form of "iso mount" to aid remembering the alias, it's purpose, and to differentiate it from any other command or alias. Similarly "umnt" is a unique shortened form of "umount"

FYI: To break down the alias imnt: sudo="as root": "mount -o loop"="mount as if it were a block device": ./="from this directory": *.iso="any file with the extension .iso": ~/Desktop/iso="to a directory named "iso" located on this users desktop"

FYI: To break down the alias umnt: sudo="as root": umount="unmount": ~/Desktop/iso="whatever is mounted to a directory named "iso" located on this users desktop"

You could just copy/paste the lines into .bashrc, but this way you have a separate .alias file to keep them, and any other aliases you may wish to add in the future, and don't clutter up .bashrc.

Now to use this, open the Konqueror file browser, and navigate to the directory that contains the ISO image you want to mount. From the "Window" menu, choose "Show Terminal Emulator", and simply type, at the prompt:

$ imnt

Your ISO image is now mounted in the "iso" directory on your desktop, and you can browse it to your hearts content, and copy files from it to other directories, if you wish. Remember it's a mounted image, of a read only file system, so you can't copy files to it, only from it. One caveat to this working is that the ISO image you want to mount must be the only ISO image in the directory. If you have a directory with a number of ISO images, you must first separate them into their own private directories, within the main directory.

To unmount the ISO image, from any terminal window type, at the prompt:

$ umnt

Now, if you have followed the instructions, as you were reading this, and if you have actually created and used the aliases to successfully mount, and unmount an ISO image, congratulations. Even if you are a green as grass, newbie, GUI guy/gal, (I know I said I wouldn't do that. Quit your laughing) you've learned how to accomplish a specific, desired, repetitive type task, with a minimum amount of keystrokes, using the dreaded command line, and it didn't even hurt. :)

In this article, I've tried to be a bit overly redundant with the definitions, and the FYI explanations, so that even newbies (Are Linux newbies really "gnubies"?) who are not used to command line shortcuts, and structure, will understand that it's just a way to give a simple instruction to the computer. An alias is used to save keystrokes when entering those instructions. Some of the explanations of what the syntax means might not be precisely correct, but they convey the essence of what one is requesting/commanding the computer to do, hopefully in a way that also conveys why the structure is as it is.

And what, may I rhetorically ask, do we really learn from all this? An alias is a very simple, quick, shortcut used to enter a more complicated command. What is it's true value? Efficiency. The longer, and more complicated the command, the more often one needs to use it, the greater the keystroke reduction, the greater the value of the alias.

Next time, I'll show you how to create aliases to actually accomplish some specific useful tasks, and how to join them to accomplish multiple tasks with a single alias.

Thus ends our lesson for the day.

(1) AcetoneISO2 depends on the following packages:

- fuseiso, fuse-utils, libfuse2, mkisofs, libqt4-core, libqt4-gui, konsole, konqueror, kdebase-bin, kdelibs4c2a,libfuse-dev, build-essential, cdrecord, cdrdao, dvd+rw-tools, p7zip-full, gnupg, coreutils, libglib2.0-dev

tuxmachines.org

Top