LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 09-06-2005, 01:56 AM   #1
stefaandk
Member
 
Registered: Jun 2005
Distribution: Centos
Posts: 215

Rep: Reputation: 30
recursive move


I got the '-r' for cp but not for mv.

How could I recursively move directories and content?

Cheers
 
Old 09-06-2005, 02:06 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
When you "move" a directory (i.e. unlink it and link it somewhere else), all its contents go with it, right? (Am I missing something here?)

"cp" is different in that by default it only copies files, and you need "-r" for it to copy directories.
 
Old 09-06-2005, 02:29 AM   #3
Charred
Member
 
Registered: Mar 2005
Location: Utah, USA
Distribution: Slackware 11
Posts: 816
Blog Entries: 2

Rep: Reputation: 30
Every time I've moved a directory, it's taken all its contents with it.
 
Old 10-09-2012, 07:41 PM   #4
aliqasemi
LQ Newbie
 
Registered: Sep 2012
Posts: 7

Rep: Reputation: Disabled
7 years later still no recursive option for move

recursive option has been implemented for mv only partially. It is possible to move a source directory and its contents to a destination directory if there is no directory with the same name as source in the destination. Otherwise it complains "mv SOURCE to TARGET; unable to remove target: Is a directory". Apparently the mv command is too stupid to know that there is a possibility to skip removing the target and instead continue on moving the contents recursively. This makes people like me upset as there is no other simple command-line solution to achieve exactly the same behaviour.

Last edited by aliqasemi; 10-09-2012 at 07:45 PM.
 
Old 10-09-2012, 07:48 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Code:
cp -r $SOURCE $DESTINATION && rm -r $SOURCE
Simple enough?
By the way, the GNU tools are open source, if you really need that function just because you don't want to use to commands for that functionality feel free to extent the mv command.

Last edited by TobiSGD; 10-09-2012 at 07:51 PM.
 
Old 10-09-2012, 08:14 PM   #6
aliqasemi
LQ Newbie
 
Registered: Sep 2012
Posts: 7

Rep: Reputation: Disabled
Quote:
Originally Posted by TobiSGD View Post
Code:
cp -r $SOURCE $DESTINATION && rm -r $SOURCE
Simple enough?
By the way, the GNU tools are open source, if you really need that function just because you don't want to use to commands for that functionality feel free to extent the mv command.

"cp -r $SOURCE $DESTINATION && rm -r $SOURCE" is not a good option when you want to move big directories between different computers, which take long and there might be interruption. you are right nevertheless, for the moment I complained so that if somebody is more expert and has the time to do it ;-).

Edit:
This option is already implemented in nautilus, which is gpl licenced as well. It asks if you want to merge the folders or not, and there is a apply-to-all check-box. But one have to dig into the codes to transfer the functionality to the mv command

Last edited by aliqasemi; 10-09-2012 at 08:27 PM.
 
Old 10-09-2012, 08:22 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
If you are worrying about interruptions substitute cp with rsync in that command, it copies only files that are different and can use compression if needed (and appliable).
mv and cp are simply not the right tools for that.
 
Old 10-09-2012, 08:36 PM   #8
aliqasemi
LQ Newbie
 
Registered: Sep 2012
Posts: 7

Rep: Reputation: Disabled
Thank you very much for your help. The rsync command, specially when used with --remove-source-files option does exactly what I want. (well hopefully, haven't tested it yet)
 
  


Reply



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
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 12:01 PM
Recursive Question Mistro116@yahoo.com Programming 1 11-27-2005 05:29 PM
Recursive Copy fizgig10 Linux - Newbie 1 07-16-2005 11:58 PM
Recursive compilation Genjix Programming 1 12-07-2004 07:23 AM
rm -r what is recursive wogga Linux - Software 3 05-28-2004 02:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:35 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
Open Source Consulting | Domain Registration