Unix/Linux Go Back    


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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
gnnsprapa's Unix or Linux Image
gnnsprapa gnnsprapa is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 17 January 2018, 2:06 AM EST
Posts: 45
Thanks: 6
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 Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
ashok.mp87's Unix or Linux Image
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 06:10 AM.. Reason: code tags
Sponsored Links
    #3  
Old Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 January 2018, 2:12 PM EST
Location: Aachen, Germany
Posts: 11,968
Thanks: 354
Thanked 3,688 Times in 3,386 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 Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
gnnsprapa's Unix or Linux Image
gnnsprapa gnnsprapa is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 17 January 2018, 2:06 AM EST
Posts: 45
Thanks: 6
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.

Linux
Sponsored Links
    #5  
Old Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
ashok.mp87's Unix or Linux Image
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 07: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 Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
hicksd8's Unix or Linux Image
hicksd8 hicksd8 is offline Forum Staff  
Moderator
 
Join Date: Feb 2012
Last Activity: 22 January 2018, 5:28 PM EST
Location: Devon, UK
Posts: 1,734
Thanks: 248
Thanked 440 Times in 377 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 Unix and Linux 03-23-2017   -   Original Discussion by gnnsprapa
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 22 January 2018, 6:04 PM EST
Location: San Jose, CA, USA
Posts: 10,937
Thanks: 611
Thanked 3,823 Times in 3,267 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.

Linux
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
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:50 AM
Move files from Space Folder to other folder kannansoft1985 Shell Programming and Scripting 2 08-22-2014 12:59 PM
Move files to another folder base on DU Gavisht Solaris 5 10-03-2012 03:53 AM
Move only files to a folder brnl_basu Shell Programming and Scripting 4 06-23-2011 05:40 AM
move files to some folder learnbash Shell Programming and Scripting 2 07-20-2010 05:37 AM



All times are GMT -4. The time now is 08:01 PM.