LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-13-2012, 04:56 AM   #1
lofijerm
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Rep: Reputation: Disabled
plucking a single file from multiple folders


Hello,


I have 'x' amount of folders in directory 'b'. Each folder has 2 files. One file ends in .avi, and the other is .whatever. No files are named the same.

How would I go about plucking the .avi file from each folder into directory 'b' in one swift move? Should I be using '*' or '?' in the terminal?

I could just go through each folder dragging and dropping the file I want, but I do this a lot and I need a solution. Anybody?
 
Old 02-13-2012, 05:11 AM   #2
sys64738
Member
 
Registered: May 2008
Location: NRW/Germany
Posts: 105

Rep: Reputation: 30
Hello,

Code:
find . -name "*.avi" -exec mv {} /path/to/b \;
that should do the job. If you also have files ending in *.AVI you could replace -name with -iname
which doesn't care about upper or lower letters.
 
1 members found this post helpful.
Old 02-13-2012, 05:15 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Try the find command which is recursive by its nature:
Code:
find /path/to/b -mindepth 2 -name \*.avi -exec echo mv '{}' /path/to/b \;
The echo statement will display the commands to execute, without actually executing them. Check the result, then run again without echo.
 
1 members found this post helpful.
Old 02-13-2012, 05:26 AM   #4
lofijerm
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Very swift indeed! Cheers to both of you.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple file pointers in a single file? altoz Linux - Server 3 04-20-2011 10:37 AM
Multiple Folders to a Single Path yermandu Linux - Server 4 04-14-2010 04:18 PM
Is multiple owners of a single file possible? can user1 own a file that root also own dave247 Debian 3 10-09-2008 04:53 AM
Copying a single file to multiple directories quest49 Linux - Software 6 12-04-2006 08:07 AM
Changing file permissions within multiple folders cloudxiii Linux - Newbie 1 02-21-2005 12:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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