LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-23-2015, 04:28 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,223

Rep: Reputation: Disabled
Post Move and Extract specific files from sub-directories into parent directory.


Hello all.
I have 100 sub-directories that "rar" files exist in them, How can I move all rar files into parent directory?

I used "find sourcedir -type f -exec mv {} targetdir \; " but i just copy one file and all files deleted

Thank you.

Last edited by hack3rcon; 05-23-2015 at 10:49 AM.
 
Old 05-23-2015, 05:15 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
Quote:
Originally Posted by hack3rcon View Post
I have 100 sub-directories that "rar" files exist in them, How can I move all rar files into parent directory?
Saying "sourcedir" and "targetdir" here is meaningless as you may have mistakenly let the target directory be a relative path or a subdirectory elsewhere. So be verbose and precise what nfo you post. There's valid reasons to avoid using "-exec" and one of them, especially if you're not certain about ops, is that 'xargs' allows you to review what it thinks it should perform ("-p") and be verbose about what it does ("-t"):
Code:
find /exact/source/path -type f -iname \*.r?? -print0 | xargs -0 -iF -p /bin/mv -f 'F' /exact/destination/path

Quote:
Originally Posted by hack3rcon View Post
i just copy one file and all files deleted
If you haven't misplaced things then next time ask before doing?
 
Old 05-23-2015, 06:13 AM   #3
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,223

Original Poster
Rep: Reputation: Disabled
worked but all files in sub-directory have same names, How can I move and rename?

Last edited by hack3rcon; 05-23-2015 at 06:15 AM.
 
Old 05-23-2015, 06:27 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
Quote:
Originally Posted by hack3rcon View Post
all files in sub-directory have same names,
Shouldn't you have said so in your initial post?..


Quote:
Originally Posted by hack3rcon View Post
How can I move and rename?
What have you tried yourself?
Rename file names based on what criterion?
 
Old 05-23-2015, 08:01 AM   #5
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,223

Original Poster
Rep: Reputation: Disabled
Oh sorry, I forgot it
 
Old 05-23-2015, 08:22 AM   #6
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,223

Original Poster
Rep: Reputation: Disabled
I use this command and problem solved :

find . -name "*.rar" -exec unrar x -o {} \;
 
  


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 move seleted directories to specific directories by putting condition VijayB Linux - Newbie 3 07-05-2014 04:31 PM
find files but move the parent directory instead? Springs Linux - General 4 12-21-2012 12:27 PM
Copy a directory into another directory while ignoring specific directories or files wh33t Linux - Newbie 14 05-16-2012 09:13 PM
[SOLVED] Find files with specific extension and move to a directory moyorakkhi Linux - Newbie 10 04-19-2011 09:50 AM
[SOLVED] move all ".txt" files, adding parent directory to filename mostofmonty Linux - Newbie 9 09-15-2009 09:39 AM

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

All times are GMT -5. The time now is 05:25 AM.

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