Centos7 /etc/profile和/bin被誤刪除的解決辦法
/etc/profile被刪除的解決辦法
/etc/profile被誤刪除了,ls、vim等shell命令都報如下錯誤:
-bash: /usr/bin/ls: Argument list too long
shell命令基本都在/usr/bin,/usr/sbin,/bin,/sbin,/usr/X11R6/bin中有定義,
因此通過下面這條命令,重新取出shell命令
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin
新建立/etc/profile文件
通過vim /etc/profile新建立profile文件,把如下命令拷貝進去,再使用source /etc/profile是文件立即生效
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`id -u`
UID=`id -ru`
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
#ulimit -SHn 1024000
/bin被誤刪除的解決辦法
使用source /etc/profile報如下錯誤:
-bash: /usr/libexec/grepconf.sh: /bin/sh: bad interpreter: No such file or directory
(base) [root@kafka1 etc]# source /etc/profile
-bash: /usr/libexec/grepconf.sh: /bin/sh: bad interpreter: No such file or directory
發現是/bin目錄被誤刪除,此時ssh遠程連接服務器時,會無法連接:報錯Permission deny,用戶名或密碼不正確。
補救辦法是,在linux服務器上查找bash文件
(base) [root@kafka1 /]# whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz
如下圖所示:直接建立/bin目錄到/usr/bin目錄的軟連接
創建軟鏈接ln(link)的方法:
ln -s 源文件 目標文件
-s 選項,表示創建軟連接。
源文件 就是要連接到的文件
目標文件 就是要創建的軟連接文件,目標文件可以看作源文件的快捷命令
具體命令如下:
ln -s /usr/bin /bin
建立軟連接成功後,再source /etc/profile即可成功
source /etc/profile