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 06-27-2009, 11:37 AM   #1
budword
Member
 
Registered: Apr 2003
Location: Wisconsin
Distribution: Switched to regualr Ubuntu, because I don't like KDE4, at all. Looks like vista on crack.....
Posts: 675

Rep: Reputation: 31
command tofind files by extension through a directory tree, and copy them all to the


Ok, I should know how to do this already, but I don't, and google didn't help me find exactly what I want, so I'm here to pick the brains of people smarter than I.

I want to search down through a directory tree and find files with a certain extension, then cp or mv them all to the same directory.

For example. I want to find all the .txt documents in my home dir, and copy or move them all to my /home/me/doc dir. They could be in any of /home/me/text/words /home/me/text/sentences or /home/me/text/pdf.

I'm sure there is a simple command for this, but "ls | grep .txt | cp" type stuff I've tried doesn't work.

Thanks much for setting me straight.

David
 
Old 06-27-2009, 11:54 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
mv -f /home/me/text/*/*.txt /home/me/doc


Something pretty much like the above ought to work!

Sasha

Last edited by GrapefruiTgirl; 06-27-2009 at 11:57 AM. Reason: Oops - there's no -R option for mv
 
Old 06-27-2009, 01:48 PM   #3
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
find can do what you want when used with the exec action.

Code:
man find
If the GNU documentation is on your system you can get even more details and examples with:

Code:
info find
As an example, I chose not to move any files because I don't know anything about your system. Instead, I'll show one way to find all C source files from the current directory down which use the SDL libraries.

Code:
find -iname '*.c' -exec grep -q SDL '{}' ';' -print
Note that even though the above command should be quite harmless, there may be security concerns connected with the exec action as explained in the GNU find documentation.
 
  


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
How to copy files from an entire directory tree using terminal commands??? lusius188 Linux - General 3 04-10-2006 12:23 PM
Copy all files with .htm extension dickb Linux - Newbie 3 06-28-2005 01:21 PM
locate and copy files - without directory tree rodda Linux - General 1 01-16-2005 03:10 AM
How to copy tree without files in it? BladeRunner Linux - Newbie 6 03-22-2004 02:01 PM
How to copy a directory tree without copying the files in it? system Linux - General 2 01-15-2002 10:36 PM


All times are GMT -5. The time now is 01:42 PM.

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