Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Move files from one folder to another along with directory indicator

👤 Login to reply

    #1  
Old 03-23-2017
gnnsprapa gnnsprapa is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 22 May 2018, 6:55 AM EDT
Posts: 51
Thanks: 7
Thanked 0 Times in 0 Posts
Move files from one folder to another along with directory indicator

Hi All,

I have directory and it has multiple sub directories and all these sub directories contains many files. i want to move all these files to one different directory. But after moving files i should be able to recognize which file belongs to which directory.

Is there any way to achieve this.

TIA
Sponsored Links
    #2  
Old 03-23-2017
ashok.mp87 ashok.mp87 is offline
Registered User
 
Join Date: Mar 2017
Last Activity: 9 April 2017, 7:20 AM EDT
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Hi,

You can use find command to move all the files from subdirectories to a different directory and also redirect the move verbose log for future reference to find file belongs to which directory earlier.

Code:
$ find sourcedir/ -type f -exec mv -v {} ts \; > move.log


Last edited by Scrutinizer; 03-23-2017 at 05:10 AM.. Reason: code tags
Sponsored Links
    #3  
Old 03-23-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 12:24 PM EDT
Location: Aachen, Germany
Posts: 13,082
Thanks: 452
Thanked 4,017 Times in 3,693 Posts
Did you search these fora? A problem very similar to yours has been solved very recently.

I can't believe it! That was your thread!
    #4  
Old 03-23-2017
gnnsprapa gnnsprapa is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 22 May 2018, 6:55 AM EDT
Posts: 51
Thanks: 7
Thanked 0 Times in 0 Posts
@ashok:

Thanks for the response, i would try it, mean while can u please tell me what each command stands for

Code:
$ find sourcedir/ -type f -exec mv -v {} ts \; > move.log

and where i should give my destination directory name.

---------- Post updated at 04:12 AM ---------- Previous update was at 04:10 AM ----------

@RudiC

Thanks for your valuable time, but i couldn't find any solution for the thread i posted recently.

Sponsored Links
    #5  
Old 03-23-2017
ashok.mp87 ashok.mp87 is offline
Registered User
 
Join Date: Mar 2017
Last Activity: 9 April 2017, 7:20 AM EDT
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Code:
$ find sourcedir/ -type f -exec mv -v {} destdir \; > move.log

This command find all the files(type -f) in sourcedir and move it to destdir.

sourcedir - Directory which contains all subdirectories
destdir - Destination directory where you need to move all files
move.log - The log file which stores the verbose result of move command

Last edited by Scrutinizer; 03-23-2017 at 06:05 AM.. Reason: code tags
The Following User Says Thank You to ashok.mp87 For This Useful Post:
gnnsprapa (03-23-2017)
Sponsored Links
    #6  
Old 03-23-2017
hicksd8 hicksd8 is offline Forum Staff  
Moderator
 
Join Date: Feb 2012
Last Activity: 21 July 2018, 4:49 PM EDT
Location: Devon, UK
Posts: 1,924
Thanks: 291
Thanked 514 Times in 433 Posts
As already said by RudiC solutions to similar questions already exist on this forum many times over, including a thread started by yourself, so please search for them.

So rather than repeat myself please read my post#6 on this thread for another possible command line to use:
https://www.unix.com/shell-programmin...s-folders.html
Sponsored Links
    #7  
Old 03-23-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 8:52 PM EDT
Location: San Jose, CA, USA
Posts: 11,414
Thanks: 651
Thanked 3,971 Times in 3,394 Posts
Quote:
Originally Posted by gnnsprapa View Post
... ... ...

@RudiC

Thanks for your valuable time, but i couldn't find any solution for the thread i posted recently.

In what way did the code suggested by RudiC in post #5 in your thread not do exactly what you requested as the 1st half of your problem? Given that suggestion, can't you try to derive a way to perform the reverse operation on your own? If you show us that you have made an honest effort to try to solve your problem, you're much more likely to get help completing it.

If you just treat this site as your unpaid programming staff, you're much less likely to get help.
The Following User Says Thank You to Don Cragun For This Useful Post:
RudiC (03-23-2017)
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rename files from multiple directories along with directory indicator gnnsprapa Shell Programming and Scripting 5 03-16-2017 07:50 AM
Move files from Space Folder to other folder kannansoft1985 Shell Programming and Scripting 2 08-22-2014 11:59 AM
Move files to another folder base on DU Gavisht Solaris 5 10-03-2012 02:53 AM
Move only files to a folder brnl_basu Shell Programming and Scripting 4 06-23-2011 04:40 AM
move files to some folder learnbash Shell Programming and Scripting 2 07-20-2010 04:37 AM



All times are GMT -4. The time now is 12:46 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?