4

I want to edit my bash.bashrc file. Before I do this I know that I should make a back-up of the original file. What do I do if I make a mistake and need to use my back-up? Do I delete the corrupted file and rename my copy to bash.bashrc, or something else? I'm going to make cowsay say fortunes in terminal so this is a low priority. I'm using Ubuntu 14.04

Allen Mershon
  • 45
  • 1
  • 6

2 Answers2

2
  1. Perform a backup

    cp ~/.bashrc ~/.bashrc.bak
    
  2. Make your changes

  3. Re-check the changed .bashrc and activate

    with

    source ~/.bashrc
    

    or simply start a new shell with

    bash
    
  4. Test the changes

  5. If you experience problems restore the .bashrc

    cp ~/.bashrc.bak ~/.bashrc
    

    A source ~/.bashrc isn't helpful now. You have to logout and re-login

A.B.
  • 90,397
  • Instead of sourcing, just run bash - then you can exit that shell if things go wrong. – muru Nov 09 '15 at 08:18
0

There's couple of options if you make mistakes :

  • keep multiple copies of your personal .bashrc before making changes, so you don't have to undo edits.
  • If something goes wrong, you can always open .bashrc with a graphical text editor , like gedit, and undo changes
  • If you absolutely have to nuke the old bashrc, do cp /etc/bash.bashrc $HOME/.bashrc
  • If you need to do it through terminal, launch terminal with different shell, such as dash which comes with Ubuntu by default , open text editor such as vim or nano and undo the changes.
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • when I copy the file should I name it bash.bashrc.old? I am so new I am not sure here. Your answer seems much simpler than A.B.'s answer. As soon as I know how to handle the copying I'll give your answer a try. Allen – Allen Mershon Nov 09 '15 at 12:36
  • if you need a naming convention you can take .back for backup that is common when it comes to Linux. .old is a windows relict. But there is no difference between them as long as the old file is known as the old one by the person that like to use it. That's you right? So you can name your file after every conventional pattern you like. – Josh Nov 09 '15 at 13:45
  • @AllenMershon you can make the extensions whatever you what it to be - linux doesn't care about extensions as much as Windows. I could have my backup files say .bashrc.bak or .bashrc.crap and it still would be OK. Also, I've noticed you're always saying bash.bashrc The bash.bashrc is the one in /etc . You do know what every user has .bashrc in their homefolder, right ? – Sergiy Kolodyazhnyy Nov 09 '15 at 18:21
  • I had to create the .bashrc file in my home directory in order to get this to work, but it all went well. – Allen Mershon Nov 09 '15 at 18:23
  • @AllenMershon strange, by default users should already have a .bashrc created automatically for them. Anyway, my main point was that they're the ones you need to play with, not /etc/bash.bashrc. – Sergiy Kolodyazhnyy Nov 09 '15 at 18:25
  • @Serg Got it! just learning now how to navigate the file system, yesterday and today. Using LInux for about a month now. – Allen Mershon Nov 09 '15 at 18:32
  • Awesome ! Welcome to the Linux world and to askubuntu ! Keep on asking good questions and maybe answer a few,too – Sergiy Kolodyazhnyy Nov 09 '15 at 18:37