LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-17-2010, 10: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 10:14 AM. Reason: error
 
Old 06-17-2010, 10:27 AM   #2
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
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, 10:37 AM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
Try:

$ find /dir1/ -name igs*sp3.Z | xargs -n1 -i mv {} <path to destination directory>
 
Old 06-21-2010, 02: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, 03:14 PM   #5
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
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



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

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

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