日期:2014-05-16  浏览次数:20847 次

Linux的/etc/profile文件改错了
Linux的/etc/profile文件被修改了,导致系统启动后输完密码就重启了,怎么改回来?求高手指点。

------解决方案--------------------
从其他系统启动,修改profile文件。楼主下次修改时,为了防止万一,可以提前复制一份
--------------------
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi
--------------------

------解决方案--------------------
虚拟机更简单了,LiveCD 启动,mount,改回来,重启。
------解决方案--------------------
解决方法:在系统开机时按Ctrl+Atl+F1进入文本模式,用vi进入/etc/profile文件中将更改行删除,保存退出后,reboot后搞定。(所有命令等需要管理员权限)
 
顺便记录下修改环境变量的方法:
 
1.临时x修改环境变量(重启后消失)
 
    export PATH=$PATH:/.../bin
 
2.永久修改环境变量
 
    a.修 改/etc/profile(对所有用户都是有效的)
        vi /etc/profile
         在最后一行加入:    export PATH="$PATH:/.../bin"
 
    b.修改~/.bashrc文件:(单独用户)
         vi /~/.bashrc
         在最后一行加入:    export PATH="$PATH:/.../bin"
 
最后用echo $PATH命令查看