linux下rc.local文件和profile文件的区别

/etc/rc.d/rc.local是开机的时候init进程初始化的最后进行加载的吧?我看书上说rc.local脚本用于管理员自行设置开机启动任务
那么/etc/profile的作用跟rc.local不是差不多么,只不过一个是系统启动的时候执行的~一个是登录用户以后执行的?
作用范围都是用户?
不知道我理解的对不对

基本上是对的,rc.local的内容是开机运行的,不论有没有用户登录,可以理解成类似windows的系统服务。

/etc/profile是在某用户登陆后找不到~/.profile的情况下默认执行的登录脚本
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-04
/etc/profile被称为登录脚本,内含许多的全局变量,同时引导一些启动脚本(/etc/profile.d/*.sh),作用全体用户
登录账号时启用的是$home/.profile或者$home/.bash_login或者$home/.bash_profile

/rc.local桌面环境启动前启用,相当于win下的计算机脚本

两者的作用时间不同,很多时候某些脚本需要在系统启动前运行。

bashrc标识的,交互shell开启时启用
第2个回答  2013-09-04
我的理解:
/etc/profile 里可以设置一些环境变量等基础信息
/etc/rc.local 里一般开机启动程序
第3个回答  2013-09-04
区别就是作用的用户范围 rc.local启动的任务用于所有用户 而profile是针对不同用户的
第4个回答  2013-09-04
我认为这2个文件都是系统启动的时候执行的.
用户的配置在自己的目录下~/.profile追问

rc.local是在用户登录前就执行完了吧?

追答

是的. 用户的配置不可能在/etc下面, 再说了, 一般用户根本没有/etc的写权限

追问

那也就是说开机以后先执行rc.local然后用户登录之后如果有权限就执行/etc/profile 之后再执行~/.bash_profile如果没有权限就直接执行 ~/.bash_profile
如果脚本有交互信息只能放在profile文件内了吧
好像不对~是先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile文件

追答       When  bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file
       exists.  After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is read-
       able.  The --noprofile option may be used when the shell is started to inhibit this behavior.
       以上是man bash的原文. 不知道你看得懂不. 
       意思就是login shell会执行/etc/profile. 所以/etc/profile是影响所有用户的. 而且是登录的时候最先执行的. 然后依次~/.bash_profile, ~/.bash_login , ~/.profile. 
       rc.local应该是比/etc/profile更早, 登录之前就执行了.

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网