For people accustomed to MS-DOS commands, the following aliases can be defined so that a Unix-like operating system appears to behave more like MS-DOS:alias dir="ls"alias copy="cp"alias rename="mv"alias md="mkdir"alias rd="rmdir"alias del="rm -i"
However, some experienced users of Unix-like systems contend that this may not be a good idea and that it might just make Linux seem more confusing, rather than simpler. Instead, they advocate having Linux users become accustomed to the UNIX terminology right from the start.
I have underlined the above paragraph because it seems to me there is quite a bit of conflict within the Linux community about interoperability, not simply between Dos and Linux, or Unix, but between the variants of Linux also known as distributions. At the end of the day, it is the user which suffers.
We all know about code and how some coders like keeping their code secret, while others give their code away for all the world to see. The open-source community has grown precisely on this principle of freedom and openness, but by and large, code is still in the hands of coders, and the needs of individual communities are compromised as a result. Would you really want a world in which the only novels were written by scientists, or the only music was composed by mathematicians?
The reason why Ubuntu is so successful, is not just the easy to understand shell but the personality behind the shell which appears to be benign and the shell wants us to learn along with it, and not simply to install but to compile from source. This does not mean the Ubuntu CLI is the easiest, or best shell, and BASH still suffers from being too mathematical while the Linux support is too clinical for a lot of users. (Some might say, the problem is rather one of syntax and meaning, while others might say the problem is not simply about math but which maths, and not language, but which language?)
Now imagine being able to create different schemas of commands (using aliasing) that might confer unique advantages depending upon the target user? In other words, creating a linguistic or adaptive personality behind the computer that at the end of the day allows the user to remember and grasp the concept behind the command, and therefore to make more use of the power of the command line?
A musician might want to use the names of symphonies as the customised BASH command set; an artist could imitate the works of Dali and so on. (An interesting Ubuntu Aliases setup can be found here)
Here is more from the Linux Information Project:
Uses For Aliases
There are several types of uses for aliases. They include:
(1) Reducing the amount of typing that is necessary for commands or groups of commands that are long and/or tedious to type. These commands could include opening a file that is frequently used for studying or editing.
For example, if a user often accesses the Apache web server configuration file, which is /etc/httpd/conf/httpd.conf on Red Hat Linux 9, and uses the gedit text editor to read it, such user might type each time:
gedit /etc/httpd/conf/httpd.confHowever, this could quickly become tedious. It would be much easier to make this command into an alias and give it a short name, perhaps even a single letter, such as a:
alias a="gedit /etc/httpd/conf/httpd.conf"Then, whenever the user wants to open the Apache configuration file using gedit, all that is necessary is to type the following single-letter command and press the ENTER key:
aNote that the location of the Apache configuration file might be different on different systems. Also, ordinary users will likely only be able to open it for reading, and only the root user will be able to edit it (unless the permission settings are changed).
(2) A second type of use for aliases is specifying the default version of a program that exists in several versions on a system or specifying default options for a command. For example, the following alias would have the ls command always list all items in a directory rather than just the non-hidden ones:
alias ls="ls -a"Another example of setting a more convenient default option for a command is df, which is used to show information about each partition on the system, including name, size, amount of space used, amount of space available and mountpoint (i.e., where it is attached to the system). The default version of df shows this data in terms of one kilobyte blocks (a holdover from the days when 1K was considered a lot of storage), but the -h (i.e., human readable) option makes the data easier to read by expressing it in terms of MB (megabytes) and GB (gigabytes). -h can be set as the default option with the following command:
alias df="df -h"(3) A third use of aliases is correcting common misspellings of commands. For example, if a user has a habit of accidentally typing pdw instead of pwd, the following command will create an alias so that either spelling will work:
alias pdw="pwd"(4) A fourth use of aliases is increasing the safety of the system by making commands interactive. This forces the user to confirm that it is desired to perform a specific action and thereby reduces the risk from accidental or impulsive abuse of powerful commands. For example, the rm command, which can remove files and directories and make them virtually unrecoverable, can be made interactive as follows:
alias rm="rm -i"Likewise, the risks associated with the cp command, which is used to copy the contents of one file to another file, can also be reduced by making it interactive by default. If the name for the file to be written to does not exist in the specified directory (by default the current directory), it will be created, but if it already exists, its contents will be overwritten. Thus, creating the following alias will reduce the chances of an unintended overwriting:
alias cp="cp -i" (5) Another use of aliases is standardizing the name of a command across multiple operating systems. For example, different versions of Linux or other operating systems contain different versions of the vi text editor (i.e., vi or its clones vim, nvi, elvis, etc.), but issuing the vi command on any of these divergent systems will generally launch the particular vi clone that is resident on that system (assuming that the appropriate alias has been created). For instance, Red Hat Linux installs vim by default, but issuing the command vi launches vim because the alias alias vi="vim" is also installed by default for all users for the bash, csh and tcsh shells. Of course, the command vim can also be used, but vi is easier for most people to remember.
For people accustomed to MS-DOS commands, the following aliases can be defined so that a Unix-like operating system appears to behave more like MS-DOS:
alias dir="ls"alias copy="cp"alias rename="mv"alias md="mkdir"alias rd="rmdir"alias del="rm -i"
However, some experienced users of Unix-like systems contend that this may not be a good idea and that it might just make Linux seem more confusing, rather than simpler. Instead, they advocate having Linux users become accustomed to the UNIX terminology right from the start.
Making Aliases Permanent
The main disadvantage with the alias command is that any alias set up with it remains in effect only during the current login session (i.e., until the user logs out or the computer is shut down). Although this might not be much of a problem for systems which are rebooted (i.e., restarted) only infrequently (such as corporate database servers), it can be a nuisance for systems that are frequently rebooted (e.g., home computers).
Fortunately, however, any alias can be made more enduring (i.e., until it is explicitly removed) by writing it to the appropriate configuration file with a text editor. The name and location of such file can vary according to the system. In the case of Red Hat Linux, an alias for any user can be added to the .bashrc file in that user's home directory. Because this file is read at login, the change will not take effect until the user has logged in again.
Aliases for the root user can be made permanent by entering them in the .bashrc file in the root's home directory, i.e., in /root/.bashrc. System-wide aliases can be put in the /etc/bashrc file. The system needs to be restarted before system-wide aliases can take effect.
Removing Aliases
The command unalias, which is likewise built into bash and some other shells, is used to remove entries from the current user's list of aliases. Its syntax is
unalias [-a] name(s)For example, the following would remove the alias rm which was created in an earlier example:
unalias rmunalias removes not only aliases created during the current session but also permanent aliases that are listed in system configuration files. The -a option tells unalias to remove all aliases for the current user for the current shell.
A second way to remove an alias is by using the alias command to create a new alias with the same name. This overwrites the existing alias with that name.
A third way is to delete the alias from the appropriate configuration file using a text editor. For example, in the case of Red Hat, deleting an alias in the bash shell for a user named joe would involve removing the appropriate line in the file /home/joe/.bashrc. Likewise, an alias can be modified by editing the appropriate line in the configuration file.
No comments:
Post a Comment