-->
Page 93
You'll find at least one or two aliases defined for your system in the bashrc file under the /etc/directory.
System-wide alias definitions are entered by the root operator. You can put your own definition in the .bashrc file in your home directory, but if you're the root operator, you'll want to put in at least these three for all your users:
alias rm="rm -i" alias cp="cp -i" alias mv="mv -i"
These aliases provide at least some element of safety when deleting, copying, or moving (renaming) files. Without the -i, or interactive option, users may not think at least once before deleting or overwriting files.
You also can define aliases to build new commands, or provide variations of familiar commands to avoid typing long command-line options. For example, the ls command has many different options, but you can define several variations to make life easier. Some alias definitions you may want to try include the following:
# list the current directory using color filenames alias lsc="ls --color" # long format listing alias lsl="ls -l" # show all files except . and .. alias lsa="ls -AF" # show all file except . and .. in color alias lsac="ls -AF --color"
After you've entered these changes into your .bashrc file in your home directory, you can use the aliases by using the bash shell's source command:
# source .bashrc
Now you can type lsc, lsl, lsa, or lsac without adding the command-line options. Just make sure that you don't redefine an existing command! If you come up with some really useful aliases, make sure they're defined for each of the shells active on your system.
Just because a shell is available on the system, it does not mean that a user may use a particular shell to log in. As the root operator, you can maintain a list of acceptable shells for your system by editing the file shells under the /etc/directory. As a default, the following shells are listed in this file:
/bin/bash /bin/sh (a symbolic link to the bash shell) /bin/ash /bin/bsh (a symbolic link to the ash shell) /bin/tcsh
Page 94
/bin/csh (a symbolic link to the tcsh shell) /bin/ksh /bin/zsh
If you don't want your users to be able to use a particular shell, simply remove it from the list:
# chsh -s /bin/zsh Changing shell for bball. Password: chsh: "/bin/zsh" is not listed in /etc/shells. chsh: use -l option to see list
If you try to change your shell with the chsh command to use a particular shell for the next log in, the shell must be listed in the /etc/shells file. The chsh command complains and quits without making any changes. Note that this doesn't restrict a user from running a shell after logging in. The only way to effectively manage who may run a particular shell is to change a shell's ownership or file permissions (see Hour 21, "Handling Files," for details).
Most shells also offer a way to start and then run programs as a background process. This is a handy way to get work done, especially if you're working on a separate terminal, have limited screen space when working in X11, or have lots of memory. Although Linux offers virtual consoles when not working with X (accessed through the Alt and Function keys), and many X11 window managers offer separate desktops, you'll probably discover that you will run programs in the background many times while using Linux.
Programs are run in the background from the shell command line by using the &, or ampersand operator. For example, to start another terminal program under X11, you want the program to run in the background so that your current terminal is free for further input:
# rxvt &
This command starts the rxvt terminal, and your command-line prompt returns. The program is assigned a process number you can see using the ps, or process status command. For example,
# ps ... 291 1 R 0:03 rxvt ...
In this example, to keep the list short, not all of the running processes have been listed. You can stop the program by using the shell's U command with the program's process number:
# kill 291 [1]+ Terminated rxvt
Using the kill command is a crude way to control background programs. There is a more refined approach that uses other shell commands. Depending on your current shell, you
Page 95
can put running programs into the background, suspend the program, continue to run the program in the background, kill the program, or bring the program back to the terminal display. This is known as job control.
If you're running the bash shell, put a running program into the background and suspend its operation by holding down the Ctrl key and pressing the z key on your keyboard:
# pine ... program is running... (ctrl-z)... Pine suspended. Give the "fg" command to come back. [1]+ Stopped (signal) pine # fg .... program returns
JUST A MINUTE |
In order to be able to suspend the pine mail program, you must enable suspension using pine's configuration menu. While running pine, press the s key, and then the c key. Then, scroll through pine's options until you highlight "enable-suspend," and press the x key and then the e key, followed by the y key, to save the changes. You'll now be able to suspend the pine mailer. |
Sending a running program into the background and suspending its operation may be followed by the fg command to bring the running program back to your display, or by the bg command to continue to allow the program to run. This can be handy if you want to start a program, such as a newsreader (discussed in Hour 11, "Configuring Internet Email," and Hour 12, "Configuring Internet News"), then suspend and continue to run the program during lengthy operations (such as updating an internal list of newsgroups) while you run other programs in the foreground.
Using the bash shell, you can start, suspend, and run a number of programs, then selectively bring a background program back to your display by the program's job number:
# pine ... program is running (ctrl-z)... Pine suspended. Give the "fg" command to come back. [1]+ Stopped (signal) pine # sc .... program is running (ctrl-z)... [2]+ Stopped sc # fg %1 ... pine program returns...
In this example, the pine mail reader has been started, then suspended in the background to start the sc spreadsheet. Because pine is the first job suspended, the bash shell assigns