Aliases on the Zaurus

Here are some of my favorite console shortcuts.

If you get tired of typing the same thing over and over and over again, that is where simple aliases and scripts come in. To permanently store an alias, simply put it into your .bashrc file, and it will be available the next time you open your console.

An alias is kind of like shorthand...you type it, and bash enters the long stuff it is equivalent to in it's place.

I do not know about you, but I sometimes find getting the syntax straight on complicated commands to be really difficult. Aliases also provide a solution to that for commands I want to use often, when I could easily mess up getting the details straight. They make the command line a little more friendly.

So, to see how much free buffer space I really have, I entered the following, all on one line in my .bashrc file:

alias buff="free | sed -e '/[Tt]otal/d;/Swap/d'| cut -b 65- "

and then when I type "buff", I get:

bash-2.05# buff

If you know how (or are not interested in learning how) to edit the .bashrc file, then skip to here. If you do not know how to add something to your .bashrc file, I suggest reading the quick "vi" tutorial at http://networking.ringofsaturn.com/Unix/learnUNIXin10minutes.php, which was originally at freeengineer.org/learnUNIXin10minutes.html, or another resource from my Linux newbie page, and then entering the following command in your console:

bash-2.05# vi .bashrc

That will open up your .bashrc file for editing. I would then enter an escape (a quick "Cancel" on the hardware keyboard on the sl5500), which should bring up the colon as a prompt, and type the following three lines, which will add the alias on a new line at the end of your file:

alias buff="free | sed -e '/[Tt]otal/d;/Swap/d'| cut -b 65-"

You should see "Hit Return to Continue" at the bottom of your screen. Hit your "return". Then, if you didn't make any typing mistakes, enter an escape to bring up the command prompt again, and enter the following to save your changes and exit from vi:


If you made a mistake, then, since I do not want to completely explain how to use vi now, I suggest you enter an escape and then the following after the prompt (i.e., a colon ":") is presented to you, to exit vi and either read a tutorial or go somewhere to get help.


If you get really stuck, you can always just close the console, but that will leave the "vi" job hanging and require knowing how to kill that job and remove the partly edited copy of your file from the /tmp/ directory, before you can attempt to edit the file again.

Note that you can enter a temporary alias, from the command line, that will only last as long as your current bash session in the console. Any aliases you put in your .bashrc file, will not take effect until your next console session with bash.

Another favorite of mine clears buffer space. Note that there is a regular Linux "clear" command, so you will probably want to give this alias a different name if you use the *real* clear that is on your system:

alias clear="find / -name xxxx >/dev/null;free"

Please note that the above alias is currently resulting in "Out-of-Memory" warnings on my system, which it should not be doing. It worked fine for many months for me, and I think it just is a clue that I need to clear my cache by restarting Qtopia (from the Shutdown tab), or do a soft reset.

Yes, once I restarted Qtopia, my "clear" alias started working fine again. Sometimes crazy things happen with the Zaurus, often if an application crashes, tries to start and remains in the background when there is not enough memory for it to run, or you shut down the console without closing an application you started from the command line. Then an extra copy of that application is somehow stored somewhere invisible to us, and uses up a lot of memory. If the above alias causes problems for you, consider killing the offending process, restarting Qtopia, or rebooting to clear the cache on your Zaurus.

Anyhow, returning to aliases, this one opens lynx and takes me directly to oesf:

alias oesf='lynx http://www.oesf.org/forums'

I often want to read the contents of a set of files containing a specific keyword pattern when I am searching for information in my Inbox. The command I usually would enter would be something like the following:

grep -l "keyword pattern" tkcMail/Inbox/cur/* | xargs cat |less

But I get very tired of having to keep typing "| xargs cat | less", so I wrote the following alias that I use instead:

alias catless="xargs cat | less"

And then all I have to do is type "| catless" as in the following example. I suppose the alias could include the pipe as well, but I decided that would confuse me so I use "catless" as a command:

grep -l "keyword pattern" tkcMail/Inbox/cur/* | catless

Have you ever wanted to edit or view a set of files and gotten tired of copying and pasting the file names into the command line? For example, let's say I want to edit just a few of the most recent text files I have in my home directory? I could get a list of them as follows if they can be indicated with an asterisk:

bash-2.05# ls file*txt

But if I want a combination of recent files that have nothing in common other than the "txt" ending to the file name and their recency, I can use the head and tail commands, along with the "-t" option of "ls", to give me the file names. If you are not familiar with these commands and their options, check out my Linux newbie resources pages.

bash-2.05# ls -t *txt|head -n7|tail -n5

And then, after I get the list of file names, I can copy and paste the filenames to enter into the following command:

bash-2.05# vi inbox.txt clay-Feb08.txt tubes.txt basicsheets.txt sunday.txt

But, why go to all that work when I can use an alias? I call this one "space", and I "pipe" the results of the "ls", "head" and "tail" commands through it as follows:

bash-2.05# alias space="tr '\n' ' '| sed 's/ $/^M/;G'"
bash-2.05# ls -t *txt|head -n7|tail -n5|space
inbox.txt clay-Feb08.txt tubes.txt basicsheets.txt sunday.txt^M


The one problem with this version of "space" is that it puts a control M "^M" at the end of the file list. But I found that when I did not do it that way, I ended up with the list being on the same line as my next bash prompt, making it hard to copy and paste just the filenames. I am showing you the above version because I do not like the way I removed the CTRL-M, and am not convinced it will work with other versions of the commands involved.

Anyhow, I finally settled on the following final version of the alias, which works for me on my Zaurus. If it does not work for you, try the above version instead.

bash-2.05# alias space="tr '\n' ' '| sed 's/ $/^M/;G'|sed 's/..$//'"
bash-2.05# ls -t *txt|head -n7|tail -n5|space
inbox.txt clay-Feb08.txt tubes.txt basicsheets.txt sunday.txt


To call my dialup script and save all output, including standard error, to a file on my SD card:

alias qdb="~/qdial-c &>/mnt/card/qd-debug"

To raise any backgrounded opie-sh popups, instead of having to worry about remembering the correct qcop syntax, I entered this in my .bashrc:

alias raise="qcop QPE/Application/opie-sh 'raise()' > /dev/null 2> /dev/null"

To fax a single page to my friend "j", and only have to add the name of the file to be faxed, I put the following line in .bashrc:

alias jfax="efax -d /dev/ttyS3 -t T1170,,*82,,555-1212"

And then to send an fax from my Zaurus, all I have to do is enter:

jfax myfile.txt

To ssh without having to type in my username, the dns name, and the correct port number, I wrote an alias of the following format, and then all I have to do is enter a single letter and let bash enter the rest for me:

alias g='ssh -l sdjf -p 99955 geek.org'

Or, for more clarity, here's another rendition of the above:

alias g='ssh -l loginname -p portnumber servername'

My "comma" alias is a simple modification of the "space" alias I described above. I use it to simplify my typing when I need to send a bunch of uniquely named files to an ssh server using the scp command. It gives me a set of file names, separated by commas:

alias comma="tr '\n' ','| sed 's/,$/^M/;G'|sed 's/..$//'"

Using the same set of files shown in the above example for the "space" alias, here is what output looks like and an example of the output pasted into an "scp" command:

bash-2.05# ls -t *txt|head -n7|tail -n5|comma

bash-2.05# scp {inbox.txt,clay-Feb08.txt,tubes.txt,basicsheets.txt,sunday.txt} sdjf@myserver:

Here is a little more complicated example of using an alias in a bash script. We can use aliases to specify non-standard versions of built-in commands at run time, if other people are going to run our scripts.

For example, I use a fully-featured version of ps, and most of my scripts take advantage of it's features. However, many popular Zaurus ROMs use the BusyBox version of ps, and my scripts will not work properly with them. I want the scripts to be user-friendly, and I do not want people to mess up my code by trying to put the pathnames to their particular full-featured versions for all calls of the ps command, because they may not catch them all or may mess something else up.

So, an alias is the perfect remedy in this case. I can let people enter the pathname to their particular ps as the first argument on the command line. Then I can insert the following near the beginning of my script:

if [ $# -gt "0" ]; then
   alias ps="$1"

What the above does is test for the presence of command line arguments, and then put the contents of the first one into my alias for ps.

Or I can test for just the presence of $1 and accomplish the same thing:

if [ "$1" ]; then
   alias ps="$1"


Revised November 7, 2018