About the loss of the. bansh_profile Profile Profile Profile causing - bansh-4.2# problem

Keywords: Anaconda vim


First, describe the process of the problem: carelessly cp a lot of files go to / root / below, go to / root / below to execute ll to find a lot of files, so it's too troublesome for me to find the files I need. So I rm - rf /root / and rm - F / root / will / root / will / root / All the files in the directory were deleted. At that time, it was thought that deletion in this way was normal and had no side effects. However, the problem will come later, found that as long as su goes to root users will appear - bash-4.2 # at the beginning of the command line, the previous is [root@localhost~] #, which must be a problem ah, although the following commands will not be affected, but the path ahead can not be seen, this is very sad!

So Baidu found that it was because the hidden file ". bash_profile" under / root / was lost. It was only found here that when deleting the files under / root / it was deleted completely, and did not notice the hidden file. The problem is obvious when we get here. Okay, the next step is to fix the problem! ___________ But there is a problem before the repair is that some of the online said that it is OK to copy the. bash_profile file directly from the ordinary user's home directory to the / root / directory, but not after the test. It was very simple that the two files were different. Let's first see if the.Bash_profile files for ordinary users user1 and user2 are the same:

[root@localhost ~]# vimdiff/home/user1/.bash_profile /home/user2/.bash_profile

 

 

 

 

It turns out that ordinary users are the same, so let's see if the same is true between root users and ordinary users.

[root@localhost ~]# vimdiff  .bash_profile /home/user1/.bash_profile

 

This is a screenshot, see the difference, so to copy. bash_profile from ordinary users, but also to modify a little file, is to delete the red area, that is to delete ".local/bin:$HOME/".

 

Okay, here we are. The principle files are almost all there. Next, we will simulate the error environment and recovery process.

First, go to / root / below ls - al | grep ". bash_profile" to see if there is. bash_profile without deleting / root / hidden files.

[root@localhost ~]# ls -al | grep".bash_profile"
-rw-r--r--. 1 root root   176 Apr 12 16:18.bash_profile
-rw-r--r--. 1 root root 12288 Apr 12 12:41 .bash_profile.swp

It turns out that there is a file called'.bash_profile'! Next we delete it

[root@localhost ~]# rm -f .bash_profile
[root@localhost ~]# ls -al | grep".bash_profile"
-rw-r--r--. 1 root root 12288 Apr 12 12:41 .bash_profile.swp

We can see that it was deleted, and here we have simulated the lost. bash_profile file environment. Next, let's look at the consequences of losing this file:

[user1@localhost ~]$ su -
Password:
Last login: Wed Apr 12 16:18:58 CST 2017 onpts/0
-bash-4.2# ls
anaconda-ks.cfg  initial-setup-ks.cfg
-bash-4.2# pwd
/root
-bash-4.2#

The result is not very strange. When we switch to root, it's not [root@localhost~] #, but - bash_4.2 #. So we can't see the current working directory at first sight. It's very uncomfortable. Then we go to restore the file of. bash_profile. If we had backup/root/file before, it would be easy to do. Direct cp to / root / is OK, but before it was deleted directly, no backup, no original. Then go to the ordinary user to copy and modify a. bash_profile file to / root / file.

First copy the file to the root home directory:

-bash-4.2# cp  /home/user1/.bash_profile  ./
-bash-4.2# ls -al | grep".bash_profile"
-rw-r--r--. 1 root root   193 Apr 12 19:09.bash_profile

Modify the. bash_profile file:

-bash-4.2# cat ./.bash_profile
# .bash_profile
 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
         .~/.bashrc
fi
 
# User specific environment and startupprograms
 
PATH=$PATH:$HOME/.local/bin:$HOME/bin
 
export PATH
-bash-4.2# vim ./.bash_profile
-bash-4.2# cat ./.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
         .~/.bashrc
fi
 
# User specific environment and startupprograms
 
PATH=$PATH:$HOME/bin
 
export PATH
-bash-4.2#

Okay, the modification is successful; let's su - refresh!

-bash-4.2# su -
Last login: Wed Apr 12 19:09:03 CST 2017 onpts/0
[root@localhost ~]#

O() O ~, found and restored, and here it is completely solved!


Posted by Nicholas Reed on Tue, 09 Jul 2019 13:20:48 -0700