Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 01: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, 02:11 PM   #2
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 395

Rep: Reputation: 70
mv dir1 /path/to/dir2/
Old 12-06-2012, 02:22 PM   #3
Senior Member
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,871

Rep: Reputation: 253Reputation: 253Reputation: 253
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, 02:43 PM   #4
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
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 09:40 AM
[SOLVED] Modify the directory entry structure of a directory to show manipulated data shreyas08 Linux - Newbie 1 12-13-2011 05:34 AM
Username & Password Sync Fedora Directory and Microsoft Active Directory karnac01 Fedora 4 07-19-2010 12:51 AM
change default vsftp anonymous accout directory /var/ftp to other directory? hocheetiong Linux - Newbie 2 01-24-2010 06:33 PM
LXer: Directory services made easy with Fedora Directory Server LXer Syndicated Linux News 0 12-08-2006 03:54 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:53 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