Monday, May 6, 2024
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 2286  / 2 Years ago, thu, may 5, 2022, 2:08:09

What is difference between these command: I used cd $HOME/directory/test/ before running each lines:



cd ~
cd /
cd ~/
cd -
cd --
cd /.
cd $HOME
cd $USR
cd


And all of these do the same behavior. What is difference?


More From » command-line

 Answers
1

The simple command cd <dir> which changes directory to <dir>.




  • ~ indicates $HOME directory

  • / indicates the root directory

  • ~/ indicates the $HOME directory as well. The only difference is that it explicitly shows it's a directory (the trailing slash). cd ~/ and cd and cd ~ and cd $HOME all do exactly the same thing.

  • cd - Changes the working directory to the previous working directory.






These special symbols "." (dot) and ".." (dot dot)[Relative Parameters]:


The "." symbol refers to the current directory and the ".." symbol refers to the current
directory's parent directory.






$USER and $HOME are Environment-Variables



$USER = The name of the currently logged-in user. This variable is set by the system. You probably shouldn't change its value manually. (ex:myuser1)



$HOME = The location of the currently logged-in user's home directory.(ex: /home/myuser1)



Recommended to use cd "$HOME" or cd "$USER" so-that cd gets proper input in case of space, etc.


[#24647] Friday, May 6, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
scrubuz

Total Points: 194
Total Questions: 96
Total Answers: 127

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;