4

I would like to move a file via the terminal using the mv command. The syntax is

mv file_old_dir file_new_dir

I am already in the directory where I want the file moved. I just did mv file_old_dir which didn't work.

How can I do this?

mv file_old_dir "here"

16

You can use the dot (.), the ~+ tilde expansion, the pwd command or the $PWD variable to represent the current working directory (CWD). All these commands can do what you want:

  1. mv file_old_dir .
  2. mv file_old_dir ~+
  3. mv file_old_dir $(pwd)
  4. mv file_old_dir $PWD
| improve this answer | |
7

I am going to show some alternate ways using the PWD environment variable and pwd built-in of the shell.

You can the use the value of PWD environment variable that stores the name of current working directory:

mv file_old_dir "$PWD"

Or you can use the pwd built-in of shell that prints the current working directory (basically pwd shows the value of PWD variable by default):

mv file_old_dir "$(pwd)"
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.