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 04-07-2006, 03:13 AM   #1
Registered: Aug 2005
Distribution: Debian 'lenny'
Posts: 208

Rep: Reputation: 30
How to move files from a subdirectory to another?

File structure:



I'm trying to move files in /temp/testdir1 and /temp/testdir2 to /temp1. When I use the command 'mv /temp/*.* /temp1', only the files in /temp/ are moved, but the subdirectories testdir1 and testdir2 are not moved to /temp1.

Any help would be deeply appreciated!

Old 04-07-2006, 03:21 AM   #2
Registered: Jan 2004
Location: On Planet Earth.
Distribution: Slackware 12
Posts: 244

Rep: Reputation: 30

try mv -R /temp/*.* /temp1
or mv -r /temp/*.* /temp1

cant remember if its capital R or not
Old 04-07-2006, 04:13 AM   #3
Registered: Aug 2005
Distribution: Debian 'lenny'
Posts: 208

Original Poster
Rep: Reputation: 30
I get invalid option for both -r and -R.

Originally Posted by synapse

try mv -R /temp/*.* /temp1
or mv -r /temp/*.* /temp1

cant remember if its capital R or not
Old 04-07-2006, 04:53 AM   #4
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
mv -R /temp/ /temp1/
That should do it. Why not just rename the temp directory?
mv temp temp1
Old 04-07-2006, 05:41 AM   #5
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
From your description, it sounds like you want to execute two separate commands:
mv /temp/testdir1/* /temp1/
mv /temp/testdir2/* /temp1/

Although, this could be combined as "mv /temp/testdir1/* /temp/testdir2/* /temp1/"

Look through the man page for "mv". There is no -r or -R option. You are thinking of the "cp" command.

If you want to move just files, and not subdirectories, then you will want to use the "find" command.

find /temp/testdir1 -maxdepth 1 -type f -exec mv '{}' /temp1/ \;
find /temp/testdir2 -maxdepth 1 -type f -exec mv '{}' /temp1/ \;

If there are only the two subdirectories testdir1 and testdir2, then the single command
find /temp/ -maxdepth 2 -type f -exec mv '{}' /temp1/ \;
would work.

Last edited by jschiwal; 04-07-2006 at 05:43 AM.


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
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 12:01 PM
Script to Move files jain_rajesh Linux - Newbie 1 10-15-2004 08:53 AM
the best way to move files around..... thegreggwong Linux - Software 5 08-28-2004 05:20 PM
I can't move files at desktop. akihandyman Mandriva 2 08-27-2004 07:38 AM
how do i move hidden files coolinuxguy246 Linux - Newbie 6 06-03-2004 01:33 AM > Forums > Linux Forums > Linux - Newbie

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

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