mv -i not working

bash-4.4$ mv -i dir2 dir3                                                                                                                          
bash-4.4$ ls -ltr                                                                                                                                  
total 12                                                                                                                                          
-rw-r--r-- 1 14392 14392  978 Nov 22 16:46 README.txt                                                                                              
-rw-r--r-- 1 14392 14392    7 Nov 22 16:47 456.txt                                                                                                
drwxr-xr-x 2 14392 14392 4096 Nov 22 16:49 dir3                                                                                                    


i tried as above but i did not get warning  like below

mv: overwrite `dir2'?


i tested with files also but no warning coming

bash-4.4$ touch a.txt                                                                                                                              
bash-4.4$ mv a.txt b.txt                                                                                                                          
bash-4.4$ ls -ltr                                                                                                                                  
total 12                                                                                                                                          
-rw-r--r-- 1 14392 14392  978 Nov 22 16:46 README.txt                                                                                              
-rw-r--r-- 1 14392 14392    7 Nov 22 16:47 456.txt                                                                                                
drwxr-xr-x 2 14392 14392 4096 Nov 22 16:49 dir3                                                                                                    
-rw-r--r-- 1 14392 14392    0 Nov 22 16:56 b.txt                                                                                                  
bash-4.4$ mv -i b.txt c.txt                                                                                                                        
bash-4.4$ ls -ltr                                                                                                                                  
total 12                                                                                                                                          
-rw-r--r-- 1 14392 14392  978 Nov 22 16:46 README.txt                                                                                              
-rw-r--r-- 1 14392 14392    7 Nov 22 16:47 456.txt                                                                                                
drwxr-xr-x 2 14392 14392 4096 Nov 22 16:49 dir3                                                                                                    
-rw-r--r-- 1 14392 14392    0 Nov 22 16:56 c.txt                                                                                                  
bash-4.4$                                                                                                                                          
           

please advise
LVL 7
gudii9Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jan SpringerConnect With a Mentor Commented:
What David said.  It protects you from overwriting an existing file.  If the file doesn't exist, you do not get prompted.
1
 
David FavorConnect With a Mentor Linux/LXD/WordPress/Hosting SavantCommented:
This will work with no errors...

mv -i dir2 dir3

Open in new window


Unless a dir3/dir2 directory already exists.

Post output of the command for more assistance...

find your-working-directory -ls

Open in new window

0
 
Dmitri FarafontovConnect With a Mentor Linux Systems AdminCommented:
drwxr-xr-x 2 14392 14392 4096 Nov 22 16:49 dir3  

dir3 already exists. mv -i gives you an interactive mode with prompts.
If you remove this mode you will have to be careful and what you are doing.
1
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
David FavorConnect With a Mentor Linux/LXD/WordPress/Hosting SavantCommented:
What Dmitri said.

In general mucking about with mv + directories... where some directories already exist is a recipe for disaster.

When you overwrite a directory (respond yes to mv -i), this destroys all files which use to live in the target directory.

I tend to only use mv to...

1) move files

2) move directories to target directories where no directory overwrite will ever occur

I alias mv to mv -i in my .bashrc file + if I ever get prompted to over write a directory, I say no... because likely I'm about to make a horrible mistake.
0
 
Dmitri FarafontovLinux Systems AdminCommented:
Plus in case of files it simply renames them. In case of directories you can cause a lot of mess if you are not careful. In either case you can destroy data if you mv one file / directory into another.
0
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
Have a look at the man page for commands you try (Advise...). From the man page on the mv command:

 -i      Cause mv to write a prompt to standard error before moving a file that would overwrite an existing file.  If the response from
             the standard input begins with the character `y' or `Y', the move is attempted.  (The -i option overrides any previous -f or -n
             options.)
0
 
skullnobrainsCommented:
you need to "mv -i -T srcdir dstdir"

then if dstdir exists, you'll get prompted

you command instructs to move srcdir into dstdir when dstdir already exists
0
 
skullnobrainsCommented:
don't care but the missing -T flag is actually the issue, here...
0
All Courses

From novice to tech pro — start learning today.