How to move all files in a directory and subdirectory? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How to move all files in a directory and subdirectory?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-01-2011
Straitsfan Straitsfan is offline
Registered User
 
Join Date: Feb 2009
Last Activity: 24 November 2014, 8:15 PM EST
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
How to move all files in a directory and subdirectory?

I'm trying to organize my MB Pro by moving all my jpeg files to a single folder from the desktop. There are some on the desktop that are not in any folder. I was at the command line and typed

Code:
mv *.jpg "Jpeg files"

but it only moved the files that were on the desktop, not any of the ones that were in any subdirectories. I'm forgetting something here -- can someone tell me how to get all the jpeg files (or any other files of a type, for that matter) -- no matter which subdirectory they're in -- and move them to the designated folder I want?

Last edited by Franklin52; 07-04-2011 at 04:04 AM.. Reason: Please use code tags for code and data samples, thank you
Sponsored Links
    #2  
Old 07-01-2011
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 November 2014, 4:08 AM EST
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts

Code:
ls -R *.jpg | while read f
do
echo mv "$f" "/Jpeg_files/${f##*/}"
done

If output fit with your needs, remove the "echo"
Sponsored Links
    #3  
Old 07-01-2011
Straitsfan Straitsfan is offline
Registered User
 
Join Date: Feb 2009
Last Activity: 24 November 2014, 8:15 PM EST
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
Can you tell me what 'echo' does in the script? I'm not clear on it.
    #4  
Old 07-04-2011
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 November 2014, 4:08 AM EST
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
echo just display the command : nothing will be done, it will just show the commands that are built.
If it builds the command as you expected, remove the echo so that it will run the move command for real.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Move files of a certain year to other directory codenjanod Red Hat 6 04-22-2010 05:33 PM
How to list directory and subdirectory? anshu ranjan Shell Programming and Scripting 7 02-22-2010 12:15 AM
Move all files in a directory tree to a signal directory? briandanielz UNIX for Dummies Questions & Answers 2 06-15-2008 06:20 PM
Find files in directory and its subdirectory jyotib Shell Programming and Scripting 11 01-24-2008 04:19 PM



All times are GMT -4. The time now is 04:14 PM.