Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: where is ~/

  1. #1
    Join Date
    Feb 2010
    Location
    nh,usa
    Posts
    161

    Default where is ~/

    OpenSuse V13.2-64, KDE

    Where is ~/ ?

    Is it the same as $HOME ?
    Regards,

    RIH5342

  2. #2

    Default Re: where is ~/

    Yes.
    ~ is a "shortcut" that expands to $HOME.

    And ~user expands to user's $HOME.
    I.e. ~test would be the same as /home/test/.
    Last edited by wolfi323; 06-Aug-2016 at 13:48.

  3. #3
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,448
    Blog Entries
    2

    Default Re: where is ~/

    Quote Originally Posted by wolfi323 View Post
    Yes.
    ~ is a "shortcut" that expands to $HOME.

    And ~user expands to user's $HOME.
    I.e. ~test would be the same as /home/test/.
    Actually, I think that last example isn't accurate...
    "~something" points to the home directory of User named "something" so you need to place a forward slash between the tilde and the name to point to a subdirectory of the User Home directory.

    Unless I'm missing something (And I did some quick testing before posting)...

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  4. #4

    Default Re: where is ~/

    Quote Originally Posted by tsu2 View Post
    "~something" points to the home directory of User named "something" so you need to place a forward slash between the tilde and the name to point to a subdirectory of the User Home directory.
    You are wrong.
    ~/username would point to /home/myself/username, not /home/username.

    ~username does point to /home/username (or whatever the home directory of the user "username" would be)

    See the difference?

    Also have a look at: https://en.wikipedia.org/wiki/Tilde#Computing

    (And I did some quick testing before posting)...
    And what exactly did you test?

    [Edit]On reading your statement a third time, you seem to mean that if you want to specify the folder xxx in your home directory, you have to use ~/xxx.
    That is true of course, but I haven't mentioned anything else.

    What I wrote was the ~xyz would point to the home directory of user "xyz".
    Last edited by wolfi323; 06-Aug-2016 at 14:47.

  5. #5
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,448
    Blog Entries
    2

    Default Re: where is ~/

    I don't know what is supposed to work with your example as follows
    I.e. ~test would be the same as /home/test/.
    If you open a console and run the following, I don't think that you'll be able to get it to return anything successfully unless you have a User called "test" and even then you won't get the result you suggested. Maybe I should be testing your syntax using something else?
    Code:
    ls ~test
    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,372

    Default Re: where is ~/

    Code:
    henk@boven:~> ls -l ~marian
    totaal 40
    drwxr-xr-x 2 marian wij 4096  1 okt  2007 bin
    drwxr-xr-x 2 marian wij 4096  8 jan  2015 Desktop
    drwx------ 2 marian wij 4096  1 mei  2012 Documents
    drwxr-xr-x 2 marian wij 4096 20 feb  2012 Downloads
    drwxr-xr-x 2 marian wij 4096 20 feb  2012 Music
    drwxr-xr-x 2 marian wij 4096 20 feb  2012 Pictures
    drwxr-xr-x 2 marian wij 4096 20 feb  2012 Public
    drwxr-xr-x 2 marian wij 4096  1 okt  2007 public_html
    drwxr-xr-x 2 marian wij 4096 20 feb  2012 Templates
    drwxr-xr-x 2 marian wij 4096 20 feb  2012 Videos
    henk@boven:~>
    As you can see the above is done by user henk and it shows the contents of the home directory of user marian (which is /home/marian btw, as configured in /etc/passwd). Exactly as Wolfi323 explains. And exactly as it is explained in the bash man page under ~ expansion:
    Tilde Expansion



    If a word begins with an unquoted tilde character (`~'), all of the characters preceding the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of the shell parameter HOME. If HOME is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name.

    If the tilde-prefix is a `~+', the value of the shell variable PWD replaces the tilde-prefix. If the tilde-prefix is a `~-', the value of the shell variable OLDPWD, if it is set, is substituted. If the characters following the tilde in the tilde-prefix consist of a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is replaced with the corresponding element from the directory stack, as it would be displayed by the dirs builtin invoked with the tilde-prefix as an argument. If the characters following the tilde in the tilde-prefix consist of a number without a leading `+' or `-', `+' is assumed.

    If the login name is invalid, or the tilde expansion fails, the word is unchanged.

    Each variable assignment is checked for unquoted tilde-prefixes immediately following a : or the first =. In these cases, tilde expansion is also performed. Consequently, one may use file names with tildes in assignments to PATH, MAILPATH, and CDPATH, and the shell assigns the expanded value.
    And this is nothing new. It was already implemented in the original sh shell on Unix ages ago.

    And ~/ is expanded as the home directory of the user typing it (or more precise: the user that owns the bash process that executes this command), and thus in my case is the same as ~henk/, both expand as /home/henk/ (because that is defined as the home directory of henk in /etc/passwd).
    Henk van Velden

  7. #7
    Join Date
    Feb 2010
    Location
    nh,usa
    Posts
    161

    Default Re: where is ~/

    Code:
      ..... explained in the bash man page under ~ expansion:
    Nice, thank you.
    Regards,

    RIH5342

  8. #8

    Default Re: where is ~/

    Hi,

    So just to make it clear that

    Code:
    ~
    and

    Code:
    $HOME
    are equal, the only difference is that the ~ does not expand inside quotes, it does not matter if it is double or single quotes. so

    Code:
    echo "~"
    does not expand while
    Code:
    echo "$HOME"
    does expand properly and that is a common mistake when someone tries to put it in a variable
    Code:
    var="~/some/directory"
    does not do what is expected.
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,372

    Default Re: where is ~/

    While I understand what you try to explain (in fact the very first ± 10 words of my man page quote above), not all above is precise
    Code:
    ~
    is a replacement for $HOME only when it is the first character of a word and a / follows it immediatetly:
    Code:
    ~/
    And then only when HOME is set (which btw will be the case more often then not). Else it will be replaced by the information found in /etc/passwd.

    I am here only repeating what I quoted above from the man page in a bit different wording.
    Henk van Velden

  10. #10
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,448
    Blog Entries
    2

    Default Re: where is ~/

    OK,
    I see what's happening...

    Perhaps, it's just me but I do my testing using a collection of descriptive namespaces...
    Whenever I use "test" it's for something generic without any special characteristics.
    If I use a namespace that has some significant characteristic, I always use a namespace that hints at that special characteristic.

    That's why you'll see in all my posts namespaces like packagename, username, user etc. and typically italicized. You'll note that in each of these namespace examples, some generic name <could> have been used but then the reader could easily use some other name and fail... for instance, for all those zypper commands if I used something generic the reader might either not substitute the name or type in an application name, both which would almost certainly fail.

    In this case where wolfi used the namespace "test" it can <only> point to a text string associated with an active and working User account. If you simply create an ordinary folder using that name, the command fails. If it points to <any> other than a valid User's home folder, the command will fail. And, this is why I said that unless you create a User called "test" the command won't work literally (without substituting the "test" name).

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •