下一页 上一页 目录

8. 定制系统

8.1 系统初始化文件

在 DOS 下,两个重要的文件是 AUTOEXEC.BATCONFIG.SYS,它们在启动时被用来初始化系统,设置一些环境变量,例如 PATH 和 FILES,并且可能启动一个程序或批处理文件。此外,Windows 有臭名昭著的注册表 --- 计算机科学史上最糟糕的主意之一。

在 Linux 下有很多初始化文件,其中一些在你确切知道自己在做什么之前最好不要去修改;它们位于 /etc 目录树中。所有的配置都可以通过编辑纯文本文件来完成。如果你只需要设置 PATH 和其他环境变量,或者你想更改登录消息或在登录时自动启动程序,请查看以下文件

FILES                                   NOTES

/etc/issue                              sets pre-login message
/etc/motd                               sets post-login message
/etc/profile                            sets $PATH and other variables, etc.
/etc/bashrc                             sets aliases and functions, etc.
/home/your_home/.bashrc                 sets your aliases + functions
/home/your_home/.bash_profile   or
/home/your_home/.profile                sets environment + starts your progs

如果后一个文件存在(请注意它是一个隐藏文件),它将在登录后被读取,并且其中的命令将被执行。

示例 --- 看看这个 .bash_profile


# I am a comment
echo Environment:
printenv | less   # equivalent of command SET under DOS
alias d='ls -l'   # easy to understand what an alias is
alias up='cd ..'
echo "I remind you that the path is "$PATH
echo "Today is `date`"  # use the output of the command 'date'
echo "Have a good day, "$LOGNAME
# The following is a "shell function"
ctgz() # List the contents of a .tar.gz archive.
{
  for file in $*
  do
    gzip -dc ${file} | tar tf -
  done
}         
# end of .profile

$PATH$LOGNAME,你猜对了,是环境变量。还有很多其他的环境变量可以尝试;例如,lessbash 等应用程序的 RMP。

将此行放在你的 /etc/profile 中将提供与 PROMPT $P$G 大致等效的功能。

export PS1="\w\\$ "

8.2 程序初始化文件

在 Linux 下,几乎所有东西都可以根据你的需求进行定制。大多数程序都有一个或多个你可以摆弄的初始化文件,通常是在你的 home 目录中的 .prognamerc 文件。你首先想要修改的是

对于所有这些以及你迟早会遇到的其他文件,RMP。也许我对 Configuration HOWTO 感兴趣,http://www.linuxdoc.org/HOWTO/Config-HOWTO.html


下一页 上一页 目录