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

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.

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

Did you search these forums? A problem very similar to yours has been solved very recently.

I can't believe it! That was your thread!

@ashok:

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

$ 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.

:b:

$ 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

1 Like

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:
How to copy files/folders and show the files/folders?

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.

1 Like