Ubuntu – How to change the value of ~

command linehome-directory

by default ~ is given the value of /home/username/

i.e. If I use the command cd ~ it goes to the directory /home/username/

How to change the value of it to some other file such as /home/username/filename?

I do know that this can be dangerous, I am working on a CTF though, so it is fine.

Best Answer

  • The tilde (~) is interpreted by your shell, as a short form of $HOME.

    Try the following commands:

    echo ~
    echo ~

    This should first print your real home directory and afterwards "foo", as you set $HOME` to that.

    The default value of $HOME comes from you system configuration. Use getent passwd to list all known users and their home directories. Depending on your system configuration those entries might come from /etc/passwd or any remote directory service.

    If you only want to temporarily redefine your home directory, just set another $HOME.

    If you permanently want to change it you have to change the passwd entry, e.g. by manually editing /etc/passwd.

    Taken from this U&L question.

  • Related Question