Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-06-2012, 02:18 PM   #1
LQ Newbie
Registered: Dec 2012
Posts: 1

Rep: Reputation: Disabled
clobbering a directory with mv

How the heck did I manage it?
I used the command
%mv dir1 /path/to/dir2
with the intent of making dir1 a subdirectory of dir2. That is, so it would end up at
But instead, mv renamed dir1 to dir2, clobbering everything in dir2. Yet I've been unable to reproduce this behavior. Trying to figure out what went wrong, I've tried
%mv test_dir1 /path/to/test_dir2
numerous times, and it's been working the way I expected and wanted: test_dir1 ends up at /path/to/test_dir2/test_dir1
Can anyone enlighten me?

In the meantime, I've aliased mv to 'mv -nv' to try to avoid future mishaps.
Old 12-06-2012, 03:11 PM   #2
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 478

Rep: Reputation: 91
mv dir1 /path/to/dir2/
Old 12-06-2012, 03:22 PM   #3
Senior Member
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 2,610

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
Directory has to exist before you can copy into it.
mv /path/dir1/* /path/dir2
Put the contents of dir1 into dir2 -n for no clobber

mkdir /path/dir2/dir1 && mv /path/dir1/* /path/dir2/dir1
Put dir1 into /path/dir2/dir1
Old 12-06-2012, 03:43 PM   #4
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,846

Rep: Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007
While I'm not sure about why that happened to you, a safer option is usually to use the -t option to explicitly specify the target directory. There's also, of course, the -n option to force no-clobber, or -i for interactive confirmation.

Adding a trailing backslash to the directory name can't hurt either, although I don't know if it has any effect here.

mv -n -t /path/dir2/ dir1


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Intel: Samsung Clobbering Others With Tizen LXer Syndicated Linux News 0 10-06-2012 10:40 AM
[SOLVED] Modify the directory entry structure of a directory to show manipulated data shreyas08 Linux - Newbie 1 12-13-2011 06:34 AM
Username & Password Sync Fedora Directory and Microsoft Active Directory karnac01 Fedora 4 07-19-2010 01:51 AM
change default vsftp anonymous accout directory /var/ftp to other directory? hocheetiong Linux - Newbie 2 01-24-2010 07:33 PM
LXer: Directory services made easy with Fedora Directory Server LXer Syndicated Linux News 0 12-08-2006 04:54 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration