2

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

Maythux
  • 87,123

2 Answers2

3

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

1

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.

Maythux
  • 87,123