Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Normally, ~ in my shell maps to /home/myuserid. How can I make it map to another directory?

share|improve this question
6  
Okay, I really, really have to know why you want this. –  Ignacio Vazquez-Abrams Nov 22 '12 at 23:55
3  
Please elaborate a bit more on the context. You should be able to solve your problem another way. –  gertvdijk Nov 23 '12 at 0:16

3 Answers 3

If you really want to do this, you can export HOME=/directory/you/want.

E.g.

~ $ export HOME=/tmp
/home/youruser $ cd ~
~ $ pwd
/tmp

But do note that this can break stuff, as noted in a comment: anything that refers to your home directory via $HOME or ~ will be broken.

share|improve this answer
3  
But expect things to start breaking left and right in any of the subprocesses. –  Ignacio Vazquez-Abrams Nov 22 '12 at 23:56

You can also assign a different path in /home/user/.bashrc for HOME environment variable.
export HOME=newpath Eg. export HOME=/home/newuser This will make the change permanent for every session and ~ will always point to another specified directory.

share|improve this answer

Different options for different circumstances:

  1. On both Linux and Cygwin, you can set the home directory temporarily by setting the HOME environment variable. Use the following command to do this (note the lack of spaces around the =)

    export HOME=/new/dir/path
    

    This is only a temporary change, and not every program will pick up on it. The setting will change if you start a new session or reboot.

  2. On Linux (at least Red Hat, and I'd be very surprised if Ubuntu differs), you can make the change permanent by running the following command (you may need to be root and/or prefix the command with sudo).

    usermod -d /new/dir/path username
    

    This is preferable to Manoj's answer, since that solution is effectively just repeating option 1 every time you open a Bash shell; not every program will pick up on the new directory.

    For this one to take effect, you'll need to restart all your sessions, or just reboot your computer.

  3. On Cygwin, for a permanent change you need to edit Cygwin's /etc/passwd file in your choice of text editor. (To do it using a Windows editor, it'll probably be in C:\cygwin\etc\passwd, but make sure you use an editor which preserves line endings, so not Notepad.)

    That file will have a line that looks something like the below:

    username:unused:23456:12345:U-GRP\username,S-1-2-34-567890-123456-789012:/old/home/dir:/bin/bash
    

    You need to change the bits between the last and second-to-last :s (which reads /old/home/dir in the above) to specify the directory you want as the user's home directory.

    Again, for this to take effect properly, you'll need to close all your Cygwin processes and reopen them, or just restart your computer to be sure of doing it properly.

Caution: Cygwin does not get on with having spaces in the home directory name. It's not supported, causes untold trouble, and the consistent response on the Cygwin mailing list when people have trouble is "well don't do that then". In particular, this means a home directory like /cygwin/c/Documents and Settings/username/My Documents is a Bad Idea™.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.