Saturday, May 4, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 706  / 3 Years ago, tue, july 6, 2021, 12:14:25

I tried cd . ~ in terminal and I saw the same result as when I type cd ~ .



I want to know how this is done. Or better to say what is the priority of the arguments which comes after a command?


More From » command-line

 Answers
6

You saw the same result because I'm sure that you test those commands from your home directory which is /home/your_username equivalent with ~ - see Tilde Expansion, or $HOME environment variable. To test properly, you should use:



cd / ; cd . ~


and:



cd / ; cd ~ .


In general if you use:



cd first_directory second_directory


you will change the shell working directory to first_directory, not to second_directory, so the second argument in the cd command is ignored (see also help cd to understand better).



And the . (dot) in this case is equivalent with the path of the shell current working directory which is given by pwd command (see Commandline shortcut for current directory similar to ~ for home directory?).



So cd . ~ is equivalent with cd . which is equivalent with cd $(pwd) and cd ~ . is equivalent with cd ~ which is equivalent with cd $HOME.


[#26239] Thursday, July 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hirtieve

Total Points: 207
Total Questions: 104
Total Answers: 114

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;