如何将.bashrc恢复为默认值?
我一直在尝试在Eclipse上安装Android开发人员工具,我按照了这个video中的信息。
就像video说的那样,我在.bashrc
文件中添加了以下两行代码:
export PATH=$(PATH):-/android-sdk/tools/ export PATH=$(PATH):-/android-sdk/platform-tools/
但是,似乎这并没有帮助我在Eclipse上安装Android文件,因为我仍然遇到问题。 更重要的是,似乎我现在无法在终端中发出任何命令而不会出现重大错误! 每次我尝试在终端中发出命令时,都会收到以下消息:
无法找到该命令,因为’/ usr / bin’未包含在PATH环境变量中。
是否有将.bashrc
恢复为默认值?
在终端中键入以下内容,
/bin/cp /etc/skel/.bashrc ~/
它将用一个新的替换你腐败的~/.bashrc
。 之后你需要~/.bashrc
以便立即进行更改,写入终端,
source ~/.bashrc
或者如果不起作用,您可以关闭终端并再次打开它。
如果你不能得到一个工作的shell
通过文件浏览器
- 打开文件浏览器,转到主目录,按Ctrl H以显示隐藏文件。 根据需要编辑
.bashrc
。 - 打开文件浏览器,转到
/etc/skel
,按Ctrl H以显示隐藏文件。 将.bashrc
复制到您的主文件夹以将其还原为默认值。
通过运行菜单
- 按Alt F2 ,键入
gedit .bashrc
,按Enter键 。 根据需要编辑。 - 按Alt F2 ,使用souravc的答案中给出的命令
/bin/cp /etc/skel/.bashrc ~/
将其恢复为默认值。
通过终端
-
打开终端,忽略你没有shell。 转到编辑 → 首选项 → 配置文件 :
-
创建新配置文件或编辑当前配置文件以更改命令:
使用
/bin/bash --norc
或/bin/bash --rcfile=/etc/skel/.bashrc
。 - 启动新选项卡(使用自定义配置文件,如果您创建了一个)。 根据需要使用工作shell。
- 删除自定义配置文件,或者在完成后编辑默认配置文件时取消选中自定义命令选项。
如果你有SSH
使用自定义命令运行SSH,这可以帮助您绕过.bashrc
:
ssh -t dash
dash
shell(aka /bin/sh
)很小,但足以恢复.bashrc
。
如果你无法获得GUI而没有SSH
启动进入恢复模式( 如何启动到恢复模式? ),这将为您提供root shell。 在/home
查找用户的主目录。
通过TTY
您可以按ctrl + alt + f1进入TTY,您必须使用您的用户名和密码登录。 ctrl + alt + f7将在稍后返回到您的GUI。
现在将/etc/skel
的现有原始.bashrc
复制到您的主目录
cp /etc/skel/.bashrc ~/
如果你不确定你的.profile
也改变了,也许甚至可以把剩下的结果带走。
cp /etc/skel/.profile ~/
现在要让.bashrc
立即生效,您可能希望使用以下内容来源代码:
source ~/.bashrc
如果您确实更换了.profile
,则需要重新启动才能使其生效。
我尝试了上面的答案,但由于某种原因,我的/etc/skel/
目录中没有正确的文件。
我在Mario Bonales的GitHub Gist上找到了默认的~/.bashrc
文件的副本 。 完整脚本将在此复制完整。
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines in the history. See bash(1) for more options # ... or force ignoredups and ignorespace HISTCONTROL=ignoredups:ignorespace # append to the history file, don't overwrite it shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) HISTSIZE=1000 HISTFILESIZE=2000 # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' #alias dir='dir --color=auto' #alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' # Add an "alert" alias for long running commands. Use like so: # sleep 10; alert alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion fi