What is the alternative for ~ (user's home directory) on Windows command prompt?

前端 未结 10 1484
离开以前
离开以前 2020-11-30 18:10

I\'m trying to use the command prompt to move some files, I am used to the linux terminal where I use ~ to specify the my home directory I\'ve looked everywhere

相关标签:
10条回答
  • 2020-11-30 18:54

    You can %HOMEDRIVE%%HOMEPATH% for the drive + \docs settings\username or \users\username.

    0 讨论(0)
  • 2020-11-30 18:54

    I just tried set ~=%userprofile% and that works too if you want to keep using the same habit

    You can then use %~% instead.

    0 讨论(0)
  • 2020-11-30 18:55

    If you want a shorter version of Jay's you could try

        set usr=%userprofile%
        cd %usr%
    

    Or you could even use %u% if you wanted to. It saves some keystrokes anyway.

    0 讨论(0)
  • 2020-11-30 18:57

    You can also do cd ......\ as many times as there are folders that takes you to home directory. For example, if you are in cd:\windows\syatem32, then cd ....\ takes you to the home, that is c:\

    0 讨论(0)
  • 2020-11-30 18:59

    You're going to be disappointed: %userprofile%

    You can use other terminals, though. Powershell, which I believe you can get on XP and later (and comes preinstalled with Win7), allows you to use ~ for home directory.

    0 讨论(0)
  • 2020-11-30 18:59

    You can use %systemdrive%%homepath% environment variable to accomplish this.

    The two command variables when concatenated gives you the desired user's home directory path as below:

    1. Running echo %systemdrive% on command prompt gives:

      C:
      
    2. Running echo %homepath% on command prompt gives:

      \Users\<CurrentUserName>
      

    When used together it becomes:

    C:\Users\<CurrentUserName>
    
    0 讨论(0)
提交回复
热议问题