10

I have set up two user logins on my computer, one for home and one for work. I would like to be able to share any of my bash and vim settings between the two users. Is there anyway to do this? Thus far, I've been copying them from one account to another, but I'd like to be able to just have one file between the two so I can make changes in only one place. Is this even possible? Thanks.

10

You can use the ln tool to create a symbolic link:

ln -s /Users/user1/.bashrc /Users/user2/.bashrc

In this example you are creating a new link for user2 pointing back to the existing file in user1's directory. You may need to use sudo ln ... if the permissions are not set correctly.

  • 4
    In this context, it probably is better to hardlink, so deleting one user account does not delete the .bashrc file for the remaining account as well. – Gerry Mar 25 '13 at 15:37
  • to do that, simply omit the -s option to the ln command – MattDMo Mar 25 '13 at 15:43
  • 2
    Even better, do this but put your bashrc in a shared Dropbox folder so it's available on every machine you use and it's backed up. – Dean Mar 25 '13 at 18:10
10

There are many ways to accomplish this, but the common idiom I've seen is to install a single file outside each user's home folder and have both ~/.bashrc files source in the common file.

This allows clarity, potential to make user-level changes at a later date, but also only maintain one file that will survive whether or not one or both users are deleted at a later date.

It's a little more work than hard linking the file and my experience in using soft links for this sort of thing is to avoid them since some tools don't handle soft (or sym) links as well as you might hope.

It's also far easier than using code control to deploy files, but that's also a great way to manage change if you are going to be setting up git or mercurial or another version control system anyhow.

  • +1 for this solution, I've implemented it with git here - github.com/balupton/dotfiles - the big benefit I've found is that I can easily install and use my custom configuration regardless of OS (osx, ubuntu, fedora, etc) as I can maintain their machine specific configuration just like normal but source in the common configuration that syncs between them. – balupton Apr 4 '13 at 16:37
7

You could edit the system-wide .bashrc, which is located in /etc/bashrc.

If you are a bit familiar with Git however, you should consider creating a repository for your "dotfiles". You can use a free Github repository to do so. Tracking your dotfiles in such a way has many advantages:

  • You can fork or pull from one of the many public dotfiles repositories available, or draw inspiration from them
  • You can easily install and update the dotfiles across different user accounts and even different machines
  • You get revision control, which might save you from some troubles in the long run
  • Also the install gives you the correct permissions – Mark Mar 25 '13 at 15:36
2

As others have noted, you can do this with a symlink, but it's also important to appropriately change the permissions so that both users can access and edit the file.

  1. Remove any existing .bashrc for user2:

    rm /Users/user2/.bashrc
    
  2. Symlink user1's .bashrc to user2's user directory:

    ln -s /Users/user1/.bashrc /Users/user2/.bashrc
    
  3. Change permissions so that both users can modify the file:

    chmod +a "user2 allow read,write,execute" /Users/user2/.bashrc
    
0

Let one be a symbolic link to the other.

In terminal.app as user2 use

cd $HOME; ln -s ../user1/.bashrc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .