2

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?

Radu Rădeanu
  • 169,590
Mohammad Reza Rezwani
  • 10,286
  • 36
  • 92
  • 128
  • What was the same result. You would only get the same result when in your home directory. Try the same example from another directory. – Dan Apr 02 '14 at 12:25

2 Answers2

5

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.

Radu Rădeanu
  • 169,590
2

It gives the same result because you're running them from your home directory. Try moving to /tmp to observe a different behaviour.

Only the first positional parameter of the cd command is taken into account:

cd: usage: cd [-L|[-P [-e]]] [dir]