Solaris Advanced User's Guide
この本のみを検索
PDF 文書ファイルをダウンロードする

Customizing Your Working Environment

10

The SunOS operating system makes it possible for you to control and adjust many aspects of your working environment. You do this by modifying the environment variables contained in your system's initialization files. When you login your system reads the initialization files and uses the environment variables to configure your system. By setting the environment variables you can "customize" your system to make it easier and more efficient to do your work.
This chapter describes how to customize your system by modifying your initialization files and setting the most common environment variables. It also describes how to alias SunOS commands, how to change your system prompt, how to set default file permissions, and how to customize OpenWindows fonts.

Initialization Files

The particular initialization files responsible for your system's configuration depend on which shell the system administrator has specified as your default shell when your system was first installed. The Bourne shell is the default shell for SunOS, but you can also use the C shell or Korn shell. Each of these shells has its own initialization file (or files).
If you're not sure which shell is your default shell (referred to as your login shell):
  1. Type echo $SHELL:


  $ echo $SHELL  
  /bin/sh  

  1. Look at the output of the command. If it is:

  • /bin/sh - your login shell is the Bourne shell
  • /bin/csh - your login shell is the C shell
  • /bin/ksh - your login shell is the Korn shell
Regardless of the shell you are using, when you first login your system generally runs the system profile file, /etc/profile. This file is generally owned by the system administrator and is readable (but not writable) by all users.
After your system executes the system profile, it runs the user profile. The user profile is one (or more) initialization files that define your working environment. For example, if you're in the OpenWindows environment your system checks this file (or set of files) each time you start a new Shell Tool or Command Tool window.
Depending on which shell is set up as your default, your user profile can be one of the following:
  • .profile (for the Bourne and Korn shells)
  • .login and .cshrc (for the C shell)
Your user profile file(s) is located in your home directory and allows you to configure your working environment to your preference.

Environment Variables

Your system sets up your system environment using a set of specifications defined in the initialization files. If you want to temporarily modify your environment for the current work session you can issue commands directly at
the command prompt. However, if you want to modify your working environment on a more permanent basis, you can store "permanent" environment variables in the .profile, .login, or .cshrc files.
To display the environment variables currently set on your system:
  1. Type the env command and press Return:


  $ env  
  HISTORY=100  
  HOME=/home/texas/keith  
  HZ=100  
  LOGNAME=keith  
  MAIL=/var/mail/keith  
  MANSECTS=\1:1m:1c:1f:1s:1b:2:\3:3c:3i:3n:3m:3k:3g:3e:3x11:3xt:3  
  w:3b:9:4:5:7:8  
  PATH=/usr/bin  
  SHELL=/bin/sh  
  TERM=sun  
  TZ=EST5EDT  


Note - You can also use the env command to identify your login shell. It is specified in the SHELL environment variable. In the example above, the shell is set to /bin/sh (the Bourne shell).

The User Profile

This section describes some of the more commonly used environment variables. Many of these variables may already be in your user profile. As previously mentioned, your user profile file (.profile for the Bourne and Korn shells and .cshrc for the C shell) is located in your home directory.

Note - Hidden ("dot") files can be listed by typing ls -la.

The following is a partial list of environment variables that can be included in your user profile. The syntax for defining environment variables depends on the shell you're using:
  • CDPATH - Specifies the directories to be searched when a unique directory name is typed without a full path name.
  • HISTORY - Sets the number of commands available to the history command (for the C shell only).
  • HOME - Defines the absolute path to your home directory. The system uses this information to determine the directory to change to when you type the cd command with no arguments.
  • LANG - Specifies the local language. Appropriate values are: Japanese, German, French, Swedish, and Italian.
  • LOGNAME - Defines your login name. The default for this variable is automatically set to the login name specified in the passwd database as part of the login process. See User Accounts, Printers, and Mail Administration for information on the passwd database.
  • LPDEST - Defines your default printer.
  • MAIL - Specifies the path to your mailbox. usually located in the /var/mail/username directory, where username is your login name. See Chapter 7, "Using Mail," for more information on this file.
  • MANSECTS - Sets the available sections of on-line man pages.
  • PATH - Lists, in order, the directories that the system searches to find a program to run when you type a command. If the appropriate directory is not in the search path, you have to enter it or else type the complete path name when you enter a command.

    The default for this variable is automatically defined and set as specified in your .profile file (Bourne or Korn shell), or .cshrc file (C shell) as part of the login process.

  • PS1 - Defines your command prompt. The default prompt for the Bourne and Korn shells is the dollar sign ($). The default prompt for the C shell is the percent sign (%). The default prompt for root in either shell is the pound sign (#).
  • SHELL - Defines the shell used by vi and other tools.
  • TERMINFO - Specifies the path name for an unsupported terminal that has been added to the terminfo database. You do not need to set this variable for default terminals in this database. See User Accounts, Printers, and Mail Administration for information on the terminfo database.
  • TERM - Defines the terminal you're currently using. When you run an editor, the system searches for a file with the same name as the definition of this variable. It first searches the path (if any) referenced by the TERMINFO variable, and then the default directory, /usr/share/lib/terminfo, to determine the characteristics of the terminal. If a definition is not found in either location, the terminal is identified as "dumb."
  • TZ - Defines the timezone for your system clock.

Setting the PATH Variable

The PATH environment variable is used to locate commands within the SunOS directory hierarchy. By setting the PATH you create a fixed set of directories that the system always searches whenever you enter the name of a command.
For example, if you have no PATH variable set and you want to copy a file, you need to enter the full pathname for the command, /usr/bin/cp. However, if you have set the PATH variable to include the directory /usr/bin, then you can simply type cp and your system will always execute the command. This is because your system searches for the cp command in every directory named in the PATH variable, and executes it when it is found. Using the PATH variable to list the commonly used SunOS command directories can thus significantly streamline your work.
For the Bourne and Korn shells, the PATH variable is specified in your .profile file (in your home directory) using the following syntax:

  PATH=.:/usr/bin:/home/bin  

where home represents the path name of your home directory.
For the C shell, the PATH variable is specified in your .cshrc file (in your home directory) using the following syntax:

  set path=(. /usr/bin home/bin)  

where home is the path name of your home directory.

Note - In the C shell you can use the shortcut ~ to represent the path name of your home directory.

If you modify the PATH variable, and you are running the C shell, use the source command to make the changes effective in your current window without having to logout:

  example% source .cshrc  

If you are running the Bourne or Korn shell, type the following to make the changes effective in your current window without having to logout:

  $ . .profile  

Aliases (C Shell Only)

Aliases are useful shortcuts for commands you often type. For example, the default setting for the remove command (rm) does not ask for confirmation before removing files. Sometimes this is inconvenient, as a typing error can remove the wrong file. However, the C shell lets you use the alias variable to change this by adding the following line to your .cshrc file:

  alias rm  'rm -i'  

With this line in the .cshrc, typing rm will now be the same as typing rm -i, which is the interactive form of the rm command. You will then always be asked to confirm the command before any files are deleted. (The quote marks around rm -i in the example above are necessary to include the blank space between rm and -i. Without them the C shell cannot correctly interpret the text after the space.
To make your changes to the .cshrc file effective immediately in your current window, use the source command. The source command causes the system to read the current .cshrc file and execute the commands in it:

  example% source .cshrc  

Changing Your Command Prompt

The syntax you use to change your command prompt depends on whether you are using the Bourne, Korn or C shell.
Bourne and Korn Shells For the Bourne or Korn shells, you redefine your command prompt with the PS1 command. The following are three examples:

  PS1=": "  
  PS1="'hostname': "  
  PS1="'hostname'{'id'}}: "  

  • The first example sets the prompt to a colon (:), followed by a space.
  • The second example creates a prompt consisting of your machine name followed by a colon and a space.
  • The third example sets the prompt to your machine name, followed by your login name in braces {}, a colon, and a space.
Type any of the examples above to change your current command prompt. The prompt will remain until you change it again, or logout.
If you want to make your changes more permanent, add one of the above examples (or a prompt of your own creation) to your .profile file. If you do this, the prompt you specify will appear each time you login in or start a new shell.
C Shell For the C shell, you personalize your command prompt with the set prompt command. The following are three examples:

  set prompt="% "  
  set prompt="'hostname'\!: "  
  set prompt="'hostname'{'id'}}: "  

  • The first example sets the prompt to the percent sign, followed by a space.
  • The second example creates a prompt consisting of your machine name followed by the history number of the command (hostname1, hostname2, hostname3, and so on).
  • The third example sets the prompt to your machine name, followed by your login name in braces, a colon, and a space.
Type any of the examples above to change your current command prompt. The prompt will remain until you change it again, or logout.
If you want to make your changes more permanent, add one of the above examples (or a prompt of your own creation) to your .cshrc file. If you do this, the prompt you specify will appear each time you login in or start a new shell.

Other Useful Variables

There are many other variables which you can set in your .profile or.cshrc files. For a complete list, refer to the man Pages(1): User Commands. The following are a few brief descriptions of some of the more commonly used options.
Use set noclobber to prevent unintentional overwriting of files when you use the cp command to copy a file. This variable affects the C shell only. Enter the following in your .cshrc file:

  set noclobber  

Use set history to set the number of commands saved in your history list. The history command is useful to view commands you have previously entered. The history file can also be used to repeat earlier commands. This variable affects the C shell only. Enter the following in your .cshrc file:

  set history=100  

You can also affect the Bourne and Korn shells in the same manner by placing the following in your .profile file:

  HISTORY=100  

Setting Default File Permissions

The umask command sets a default file permission for all the files and directories you create. For example, if you are security conscious and you want to grant members of your group, and all users, only read and execute permissions (-rwxr-xr-x) on your directories and files, you can set the umask in your.cshrc and .profile file so that every new file or directory you create is protected with these permissions.
Like the chmod command, umask uses a numeric code to represent absolute file permissions. However, the method used to calculate the code for umask is distinctly different from the method for chmod.
To begin with, if umask is set to 000, all files you create have the following (read and write, but not execute) permissions:
rw-rw-rw- (mode 666)
and all directories created have the following (read, write, and execute) permissions:
rwxrwxrwx (mode 777)
To determine the value to use for umask, you subtract the value of the permissions you want (using the value you would specify for the chmod command) from the current default permissions assigned to files. The remainder is the value to use for the umask command.
For example, suppose you want to change the default mode for files from 666 (rw-rw-rw-) to 644 (rw-r--r--). Subtract 644 from 666. The remainder, 022, is the numeric value you would use with umask as follows:

  umask 022  

Similar to the numeric code for the chmod command, the three numbers used with umask are as follows:
  • The first digit controls user permissions
  • The second controls group permissions
  • The third digit controls permissions for all others
Table 10-1 shows the file permissions created for each digit of the umask command's numeric code.
Table 10-1 umask
umask codePermissions
0rwx
1rw-
2r-x
3r--
4-wx
5-w-
6--x
7---(none)
For more information on the umask command, refer to the man Pages(1): User Commands.

Customizing OpenWindows Fonts

If you choose, you can customize the size and style of the fonts displayed in your OpenWindows applications. The following sections describe how to customize these fonts.

Specifying the Font Style and Point Size

The default font for windows is Lucida Sans in 12 point (medium); the default font for window headers is Lucida Sans Bold. If you prefer, you can specify another font style and size for windows and window headers. You can make the change for a single window or you can make a permanent change for all your applications with Workspace Properties. The following subsections describe each of these options.
Fixed-Width and Proportionally-Spaced Fonts Note that there are two general categories of fonts--fixed-width and proportionally-spaced. Each character in a fixed-width font takes up the same amount of space as every other character. By contrast, the characters in a proportionally-spaced font require varying amounts of space, depending upon their individual width. Proportionally-spaced fonts are more pleasing to the eye. However, some applications (such as Command Tool, Shell Tool, and xterm, a popular terminal emulator application) work best with fixed-width fonts.
Choosing Between Fixed and Proportional Fonts Note that the default font displayed in Command Tool and Shell Tool is a proportionally-spaced font. Although this font is pleasing to the eye, problems occur in character alignment (when spacing and tabbing) with any proportionally-spaced font in terminal windows. If the spacing and tabbing character alignment are a problem for you, it is best to choose a fixed-width font for these windows. In the examples that follow, only fixed-width fonts are used for terminal windows; the examples for other windows and headers use proportionally-spaced fonts.

Specifying the Font for a Single Window

This section describes how to open a single application with a modified font style and point size. Note that changes cannot be made to existing windows; you must start a new application to display the new font. To start a new application, you type its application name on a command line.
The basic command, shown below, specifies the application name, the -fn (font name) option, and the font style and size. The ampersand (&) returns your system prompt to the window after you type the command; this enables you to continue using that window.

  $ application -fn fontstyle-pointsize &  

The following are examples of how to use the command to open an application with a specified font style and size.
  • The example below starts a new Command Tool with the proportionally-spaced font, Lucida Sans Typewriter Bold.

    The point size is not specified; therefore the default (12-point) is used.


  $ cmdtool -fn lucidasans-typewriter-bold &  

  • The example below starts a new Shell Tool with Lucida Sans Typewriter Bold and increases the size of the font from 12 point to 14 point.

    Note that when you change the size of the font, the size of the window changes as well.


  $ shelltool -fn lucidasans-typewriter-bold-14 &  

  • The example below starts a new xterm terminal window with the font terminal-bold in 16 point:

  $ xterm -fn terminal-bold-16 &  

  • The example below starts a new Text Editor with the font Helvetica Bold in 14 point:

  $ textedit -fn helvetica-bold-14 &  

Use the -fn option with any application and any font style and size you choose. "The Available Font List" on page 158" describes how to list all the fonts available for OpenWindows applications.

Making Font Assignments Permanent

If you find that you are repeatedly running applications with customized fonts, you might like to add the customization to your workspace menu. You can do this using the Programs Menu category of Workspace Properties. This will save you the effort of typing the command-line options every time. For example, if you often want to run the text editor with a larger point size, you could add the following command line to the programs menu:

  textedit -fn lucidasans-typewriter-14  

You can have more than one instance of the same application in your programs menu if you want them to have different font sizes. This is useful if you run an application at a variety of different point sizes. For instance, you may want to have the option of running a text editor using 12, 14, or 18 point fonts. You would add the following commands to your programs menu:

  textedit -fn lucidasans-typewriter-12  
  textedit -fn lucidasans-typewriter-14  
  textedit -fn lucidasans-typewriter-18  

Once you have customized your programs menu from Workspace Properties in this way, you can invoke the text editor at any of these point sizes simply by selecting the appropriate item from your programs menu.

Note - Command lines added to the programs menu should not be followed by an ampersand (&).

Listing the Available Fonts

You may want to experiment with more fonts than have been shown in the previous examples, and you may want to apply them to other OpenWindows applications. To do this you first list the available fonts and then select them.

The Available Font List

You can see the entire list of available fonts by entering xlsfonts at the prompt in a terminal emulator window. It is best to use Command Tool to display the list because it is likely that the list will scroll off the top of the screen, and Command Tool has a scrollbar that will let you view the entire list.

Note - The list generated from xlsfonts is very long; there are over 400 fonts available. If the listing on your screen does not contain the expected number of fonts, check with your system administrator. It is possible that a subset of the available fonts was installed.

Each font has a long name in addition to a shortened version. The full name for lucidasans-typewriter, for instance, is:

  -b&h-lucida sans typewriter-medium-r-normal-sans-12-120-72-72-m-  
  0-iso8859-1  

The fonts you see in the xlsfonts listing are the long names followed by their short names. For the purposes described in this chapter, just use the short names.
Once you have chosen a font, follow the instructions in "Specifying the Font Style and Point Size" on page 155 to customize the fonts in your application windows.