LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 12-06-2012, 02:18 PM   #1
Xinc
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
/path/to/dir2/dir1
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
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 286

Rep: Reputation: 61
Code:
mv dir1 /path/to/dir2/
 
Old 12-06-2012, 03:22 PM   #3
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,826

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

Code:
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 sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.

Code:
mv -n -t /path/dir2/ dir1
 
  


Reply


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


All times are GMT -5. The time now is 02:25 AM.

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