1

I'm trying to locate where some files are stored and I can easily browse to them via ssh by going to "cd ~/foldername", however, I have no idea what directory "~/" actually is.

When I browse around folders via WinSCP (yes, I'm a Windows admin), I can't seem to locate this folder at all.

Note: I'm using Amazon Linux on EC2.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

4

The tilde character is shorthand for the home directory of the current logged-in user. If you are logged in as jason, then ~ is likely /home/jason/. It is the home directory of any username, as given in /etc/passwd. It is also the same as the $HOME environment variable. The expansion from ~ to the home directory is done by the shell.

Christopher
  • 15,911
  • That is what I thought, but I can't seem to locate the folder under my home directory. The full directory I'm looking for it "~/.ec2"...does adding that period make the folder invisible or something? I'm able to browse to it via ssh without issue, but it doesn't show up under WinSCP. – Jason Davis Jan 18 '13 at 18:14
  • I figured out my issue...I had sudo'ed to the root user to make the file I was looking for, so the folder I was looking for was actually under /root rather than /home/user.

    This information was helpful in any case though, thanks!

    – Jason Davis Jan 18 '13 at 18:16
  • Will award the answer once I'm able to in 8 minutes. Thanks for the quick response everybody. – Jason Davis Jan 18 '13 at 18:18
  • 2
    It is expanded by the shell, try echo ~. There's not even a folder with that name, because any command getting it as an argument will actually be passed the value of $HOME, not ~. – njsg Jan 18 '13 at 18:25
  • @JasonDavis Yup, this is not really a shorthand for /home/$(whoami) but for whatever your home directory is. In some systems, regular uses have those under /usr/, and I think root's $HOME used to be /. – njsg Jan 18 '13 at 18:27
  • Fantastic and quick response...thanks everybody. – Jason Davis Jan 18 '13 at 18:29
  • 2
    ~ actually expands to the current value of $HOME, not necessarily to the current user's home directory. Normally they'll be the same, but it is possible to modify the value of $HOME. (This is rarely a good idea.) On the other hand, ~foo does expand to the home directory of user foo as defined in /etc/passwd or in your system's equivalent. – Keith Thompson Jan 18 '13 at 19:03
  • @njsg, ~/file expands just to $HOME/file, and the environment variable HOME is set on login from your /etc/passwd entry (or wherever it comes from). You are free to change its value. Any resulting pain is then self-inflicted. – vonbrand Jan 21 '13 at 18:06