What directory is '~' when I type 'cd ~'?

前端 未结 11 1742
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 20:32

I\'m only new to using SSH, but when I log in I end up in the directory ~, which in general is the same directory when FTPing in. I can still go to /, but I don\'t know what

相关标签:
11条回答
  • 2021-01-05 21:11

    You can try realpath

    realpath ~
    
    0 讨论(0)
  • 2021-01-05 21:18

    ~ is an alias to the currently logged in users home directory. To find out where that really is, type pwd (stands for: Print Working Directory) right after logging in, which should give you the location relative to /. It's probably something like:

    /home/myusername
    
    0 讨论(0)
  • 2021-01-05 21:18

    Home directory need not necessarily be under /home as kigurai has pointed out.

    0 讨论(0)
  • 2021-01-05 21:20

    ~ is your home directory. To see the path type:

    echo ~
    

    in the terminal

    0 讨论(0)
  • 2021-01-05 21:21

    Yes, it is the home directory of the user you logged in as. You can use the command pwd (print working directory) to see where it is located on the file system.

    0 讨论(0)
  • 2021-01-05 21:25

    As others have commented, the tilde indicates your current $HOME directory. This may or may not be the same as the value of ~username for your user name. On my machine, $HOME and ~ both refer to /work1/jleffler. However, ~jleffler is a reference to an NFS mounted directory, /u/jleffler, as specified in the /etc/passwd file (or any equivalent database - the POSIX standard defines the behaviour in terms of the getpwnam() function; see below). My profile carefully sets $HOME. It is interesting (aka exasperating) to work out which software packages use the wrong definition of the home directory.

    For most people, ~ and ~username are the same for their user name, but that is not required. Given that you are asking the question, it is almost certainly the case that ~ and ~username are the same.

    Quote from section 2.6.1 'Tilde Expansion' of POSIX.1-2008:

    A "tilde-prefix" consists of an unquoted <tilde> character at the beginning of a word, followed by all of the characters preceding the first unquoted <slash> in the word, or all the characters in the word if there is no <slash>. [...] If the login name is null (that is, the tilde-prefix contains only the tilde), the tilde-prefix is replaced by the value of the variable HOME. If HOME is unset, the results are unspecified. Otherwise, the tilde-prefix shall be replaced by a pathname of the initial working directory associated with the login name obtained using the getpwnam() function [...]. If the system does not recognize the login name, the results are undefined.

    0 讨论(0)
提交回复
热议问题