0

How can I move a file within a directory to the current working directory without renaming?

I can mv a file from current working directory to the parent directory without renaming using the shorthand..

mv file.file ../

To move a file from a directory to the current working directory I've tried..

mv directory/file.file /

but I get permission denied.

However,

mv directory/file.file file.file

works but I have to type out the file name and the autocomplete won't work because the file isn't in the current working directory.

Isn't there a shorthand to specify the current working directory?

Thanks

0

2 Answers 2

5

To move a file to the current directory you (as you correctly surmised) need to indicate which directory to move to. This is because mv will note that the destination is a directory and will not rename the file on the way. So the...

Question Is:

How do I denote the current directory on the command line

Answer:

The current working directory is . (a single dot)

-1
$ ls 
├── foo.txt
├── bar.txt
├── dir
│   ├── foo2.txt
│   └── bar2.txt
└── dir2

for move foo2 to the working directory, use

mv dir/foo2.txt  .

To move bar.txt from the working directory to dir you can use another why

mv ./bar.txt dir
├── ../../ parent of parent
│   └── ../ parent
│        └── ./ working directory
└──

You must log in to answer this question.