2

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.

Tim
  • 32,274
  • 27
  • 118
  • 177
Tummala Dhanvi
  • 1,721
  • 3
  • 20
  • 34
  • 7
    Bad idea, that will break stuff. If you want: http://unix.stackexchange.com/questions/103666/is-it-possible-to-redefine-the-tilde-home-directory – Tim Aug 26 '14 at 11:08
  • 1
    Do you want to move your user home directory to another location? Otherwise I don't see what the purpose of your endeavour would be. You could set the environment variable `HOME` to something else, but that will break stuff… badly. – David Foerster Aug 26 '14 at 11:09
  • 2
    I am aware of it I just need the command :) I won't use it to break any thing I am working on a CTF :) – Tummala Dhanvi Aug 26 '14 at 11:11
  • What does `CTF` stand for? – Eric Wilson Aug 26 '14 at 17:54
  • @EricWilson From OP's comment on Tim's post, I guess it is "Capture the Flag". Perhaps OP is participating in some Unix golf contest. – muru Aug 26 '14 at 19:34
  • Ya CTF means Capture the flag, I am participating in a Security contest :) – Tummala Dhanvi Aug 28 '14 at 12:17

2 Answers2

5

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

Try the following commands:

echo ~
HOME=foo
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.

Tim
  • 32,274
  • 27
  • 118
  • 177
  • Tq I have got the flag in ctf :) from the link you suggested me is unix stack exchange form :) which is same as the answer :) – Tummala Dhanvi Aug 26 '14 at 11:17
3

Try to change the $HOME variable , because tilde (~) is a short form of $HOME, or change your user's home directory in /etc/passwd but that's not recommended.

Why you don't try to make and alias for cd /home/username/filename like this:

alias documents='cd ~/Documents'

Now when you type documents it will change to /home/user/Documents

More info in man alias.

To make that alias permanent, check this question.

nux
  • 37,371
  • 34
  • 117
  • 131
  • 2
    Where would you put the alias? Because if I put it in `/`, it only works (`cd aliasname`) when I am there, etc. I can't put it everywhere. – Tim Aug 26 '14 at 11:13
  • I didn't get what you are saying, can you explain it in more detail – Tummala Dhanvi Aug 26 '14 at 11:18
  • In your .bashrc file in /home/username – John Kirchner Aug 26 '14 at 11:19
  • Can you [edit] it to explain how to do this? To me an alias is a symbolic link (made with the `ln` command. – Tim Aug 26 '14 at 11:20
  • you can search @Tim i posted alias man page !!! – nux Aug 26 '14 at 11:22
  • Then this comment applies: Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Tim Aug 26 '14 at 11:22
  • at least i didn't copy and paste . – nux Aug 26 '14 at 11:26
  • 1
    I referenced, and I gave a good answer - http://meta.askubuntu.com/questions/11720/what-to-do-if-the-good-answer-is-in-another-question – Tim Aug 26 '14 at 11:36