I have messed up .bashrc & .profile in ubuntu 12.04 LTS. Can I change it back to previous version from safe mode as I am not able to login to my system and I think this might be the issue
- 84,289
- 113
2 Answers
You can do that through safe mode, just need to mount the partition in read-write mode with this command : mount -o remount,rw /. This command is necessary because in recovery mode the Ubuntu portion of hard drive is mounted in read-only mode and you cannot make changes to files. rw option tells ubuntu to allow read-write access to Ubuntu part of the disk. And yes, it is needed before running vim /home/yourusername/.bashrc.
You can get to safe mode aka recovery mode, by selecting "Advanced Options for Ubuntu" in the boot menu, then recovery mode (if you have multiple ones there, don't freak out - any of them is OK). Then access the root shell, and run the command I mentioned above. After that you can proceed with editing .bashrc or .profile with a text editor such as nano or vi
Notice also, that in recovery mode, you don't need sudo as in recovery mode you automatically logged in as root. You will also need to navigate to your nome directory to edit .bashrc or .profile by running cd /home/yourusername Notice that if you are logged in as root sudo ~/.bashrc is for root's .bashrc. Tilde expands to current users' home directory, and if you are logged in as root, it will expand to root's home directory. This is why you need to run vi /home/yourusername/.bashrc
- 105,154
- 20
- 279
- 497
First you have to notice that there is nothing called safe mode in Ubuntu. Here we have Recovery Mode.
And if you mean Recovery mode then I could say you yes you can do what you want and you can edit those .profile and .bashrc files.
You have to notice when running in recovery mode the file system usually mounted in read only mode so you have to remount it with rw.
mount -o remount,rw /
Once you do that you can able to edit the files. and note you dont have to use sudo since you'll be using root. So please be careful not to broke your system, for that I prefer you to use live CD
Or you can also use the Live CD to do the same task. Just mount your harddisk when you boot from live cd then navigate to the files and do what you want to do.
- 84,289
-
-
1You don't need sudo in recovery mode. It's run by root already – Sergiy Kolodyazhnyy May 22 '15 at 05:55
-
As serg answered above you dont need sudo, In case of live CD you can use sudo – Maythux May 22 '15 at 05:56
-
But of course when you are logged in as root,
~/won't be your home directory - you will need to use an explicit path like/home/manish/– steeldriver May 22 '15 at 11:20
mount -o remount,rw /needed before usingsudo vim ~/. bashrc? and why ? – Manish Kumar May 22 '15 at 05:56sudo vim ~/. bashrcso which.bashrcwas that in recovery mode?sudo vim /home/manish/.bashrcorsudo vim ~/.bashrc? – Manish Kumar May 22 '15 at 06:09sudo vim ~/.bashrcwas for you, for/home/yourusername. In recovery mode, you're automatically logged in as root, so ~ means/rootfolder. In recovery modevim ~/.bashrcmeans/root/.bashrcand you don't wanna edit that.sudomeans run as root, but in recovery you log in as root. It is kinda same as admin account on Windows. – Sergiy Kolodyazhnyy May 22 '15 at 06:13vim /home/manish/.bashrcright ? – Manish Kumar May 22 '15 at 06:16.bashrcand.profile? Not being logged in might or might not be related to it – Sergiy Kolodyazhnyy May 22 '15 at 06:19android_homeand i started felt sleepy so i guess i did something that i dont know when today i was trying to login my login page was bouncing back after giving correct password also. So i guess there might be some changes in those file – Manish Kumar May 22 '15 at 06:27ls -l .Xauthority? Bouncing login screen is a common problem when this file gets changed by Ubuntu automatically. Tell us whatls -l . Xauthoritytells you . If you see-rw------- 1 root root 201 May 21 22:56 .Xauthority, then this is your main problem, not .bashrc – Sergiy Kolodyazhnyy May 22 '15 at 06:30ls -l .Xauthoritylike this:-rw------- 1 manish manish 201 May 21 22:56 .Xauthority. This is correct.-rw------- 1 root root 201 May 21 22:56 .Xauthorityis not correct. You need to change ownership of that file to your username. Like thissudo chown manish:manish /home/manish/.Xauthority– Sergiy Kolodyazhnyy May 22 '15 at 06:50ls -l /home/username/.Xauthorityalso. By the way, you noticed that dot before X, right ? it's important to include it – Sergiy Kolodyazhnyy May 22 '15 at 06:56.profile&bashrcfile by following your discussion – Manish Kumar May 22 '15 at 16:56ctrl+alt+f2. – Manish Kumar May 22 '15 at 17:36