33

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

41

~/ 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 4 '11 at 20:05
  • 2
    Actually, ~ is the shorthand for current user's home folder :) – heartsmagic Dec 4 '11 at 20:17
  • 1
    I did not say invalid :) Generally we see ~ instead of ~/, since / is not necessary there. – heartsmagic Dec 4 '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 5 '11 at 2:41
  • 1
    There's no place like ~ – Foon Mar 22 '13 at 1:56
4

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 8 '18 at 0:51
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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