• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 117
  • Last Modified:

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
0
gudii9
Asked:
gudii9
  • 2
  • 2
  • 2
  • +2
5 Solutions
 
David FavorLinux/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
 
Jan SpringerCommented:
What David said.  It protects you from overwriting an existing file.  If the file doesn't exist, you do not get prompted.
1
 
Dmitri FarafontovLinux 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
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
David FavorLinux/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 MVETopic 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now