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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Security

From novice to tech pro — start learning today.