45

I'm new to Linux and Ubuntu. People keep using ~/filename in their answers to my questions. What does ~/ mean?

jrg
  • 60,611

3 Answers3

53

~/ is shorthand for the current user's home folder. So if your user name is "foobar" it expands to /home/foobar/

  • 8
    And if you want to refer to another user home directory you can use ~user, as in ls -l ~enzotib/Documents/. – enzotib Dec 04 '11 at 20:05
  • 2
    Actually, ~ is the shorthand for current user's home folder :) – heartsmagic Dec 04 '11 at 20:17
  • @heartsmagic True, but ~/ is equally valid. – Knowledge Cube Dec 04 '11 at 20:40
  • 1
    I did not say invalid :) Generally we see ~ instead of ~/, since / is not necessary there. – heartsmagic Dec 04 '11 at 20:47
  • 8
    This is only usually correct, but not technically correct. ~ actually expands to the value of the environment variable HOME. If you change the value of HOME, ~ will also no longer point to that user's home directory. – kojiro Dec 05 '11 at 02:41
  • 1
    There's no place like ~ – Foon Mar 22 '13 at 01:56
  • Tecnically ~ is what refers to the user's home folder. The slash at the end is not required, and is just equivalent to adding the slash at the end of a directory path, and will have the same effect (ie, varies according to context). That is, ~ is equivalent to /home/user and ~/ is equivalent to /home/user/. The former concisely points to the directory, the latter can be used when using that directory as the root of some operation such as a destination for copying. – thomasrutter Aug 08 '18 at 00:48
  • AND, 12 years later, this answer is still helpful. Thank you. – user1465073 Jan 17 '23 at 08:55
5

An important thing is, if you are using the root user, ~/ will be the /root directory, not /home/user_name.

In this case, do:

> cd ~/ ; pwd ;

It will exit:

> /root
  • This is a direct result of the fact that /root is listed as the home directory of the root user in your /etc/passwd table. It isn't a special case. – thomasrutter Aug 08 '18 at 00:51
2

In general the tilde ~ represents your home folder. Use it to refer to your home directory at the command line.

haziz
  • 2,929