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-17-2010, 11:11 AM   #1
alex_chartier
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Rep: Reputation: 0
Move some of the files from multiple directories to one location


Hi. I'd like to move a selection of files from all the sub-directories within an overall directory to a single destination. I don't want any of the directory structure, just the files themselves. This is what I tried so far:

mv /dir1/*/igs*.sp3.Z /dir2

There are other .sp3.Z files in the * directories within /dir1 but I just need the ones that start with igs...

Thanks, Alex

Last edited by alex_chartier; 06-17-2010 at 11:14 AM. Reason: error
 
Old 06-17-2010, 11:27 AM   #2
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 173Reputation: 173
Hi,
you forgot to tell what output gave that command.
Another way to do it would be with "find" that look for files and them mv them with -exec command.
 
Old 06-17-2010, 11:37 AM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,472

Rep: Reputation: 189Reputation: 189
Try:

$ find /dir1/ -name igs*sp3.Z | xargs -n1 -i mv {} <path to destination directory>
 
Old 06-21-2010, 03:37 PM   #4
alex_chartier
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Kilgore, that worked well for me. Now I just need to understand what it meant....
 
Old 06-21-2010, 04:14 PM   #5
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,472

Rep: Reputation: 189Reputation: 189
It's simpler than it looks. The first part is just the find command where find is asked to look in /dir1 for for all files with the requested pattern in their name(find /dir1/ -name igs*sp3.Z). If you ran just this part find would spit out every file with that pattern in dir1 and all of dir1's subdirectories. Note, find will search recursively by default so it looks in dir1 and all subdirectories of dir1. The next part uses the pipe command, "|", which takes the output of find and pipes it to the second command "xargs" for further processing. xargs receives the ouput from find and takes the files outputted one at a time(-n1) and sends that output to the curly braces,{} where the mv command sequentially acts on that input and moves the filenames received one at a time to the destination directory.
 
  


Reply

Tags
mv


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
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 05:57 PM
moving files from a location to other, preventing to move incomplete files pogo123 Programming 8 11-14-2008 07:21 AM
moving files from a location to other, preventing to move incomplete files pogo123 Linux - Newbie 2 11-13-2008 02:57 PM
Creating Multiple Directories in the same location in user space leebrent Linux - General 3 10-29-2007 01:14 PM
Move certain files into different directories facets Programming 6 05-28-2004 02:20 PM


All times are GMT -5. The time now is 10:55 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