The man for the mv
command says there's a -i
option to prompt a y/n before the command is executed, but it's not working for me. Each time I use mv -i
, the file is automatically renamed without issuing a prompt. Any idea what's going on here?
Asked
Active
Viewed 415 times
3

Doorknob
- 378
- 7
- 18

Alcuin Arundel
- 3,110
2 Answers
4
The -i
states
-i, --interactive
prompt before overwrite
Logically you are doing a "mv" where the file does not exist yet. It will only prompt if the file you are moving it to exists. Simple test:
rinzwind@discworld:~/test$ ls
rinzwind@discworld:~/test$ touch 1
rinzwind@discworld:~/test$ mv -i 1 2
rinzwind@discworld:~/test$ touch 1
rinzwind@discworld:~/test$ mv -i 1 2
mv: overwrite ‘2’? y
rinzwind@discworld:~/test$

Rinzwind
- 299,756
-
That's it. I didn't realize that -i works only when there's the potential for content to be overwritten. I was using it simply to change the file's name. – Alcuin Arundel Feb 28 '15 at 19:29
-
@AlcuinArundel no problem. Please accept mine or heemayl answer if you feel it is answered sufficiently (they basically are the same. He needs to rep so don't decide this on the 2 minutes I was quicker ;) ) – Rinzwind Feb 28 '15 at 19:32
-
OK, I just accepted your answer (I'm still getting the hang of things here :) – Alcuin Arundel Feb 28 '15 at 19:49
4
From the man page of mv
(man mv
):
-i, --interactive
prompt before overwrite
So, mv -i
will show a prompt in case of overwriting a file. Here is an example:
Only mv
:
$ touch foo.txt
$ touch ../bar.txt
$ mv ../bar.txt foo.txt ##No prompt
$ ls
foo.txt
With mv -i
:
$ touch foo.txt
$ touch ../bar.txt
$ mv -i ../bar.txt foo.txt
mv: overwrite ‘foo.txt’? y ##Prompt being shown
$ ls
foo.txt

heemayl
- 91,753
type mv
say? – steeldriver Feb 28 '15 at 18:36