Move files from one folder to another along with directory indicator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move files from one folder to another along with directory indicator
# 1  
Old 03-23-2017
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
# 2  
Old 03-23-2017
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
# 3  
Old 03-23-2017
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
@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.

Smilie
# 5  
Old 03-23-2017
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
This User Gave Thanks to ashok.mp87 For This Post:
# 6  
Old 03-23-2017
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?
# 7  
Old 03-23-2017
Quote:
Originally Posted by gnnsprapa
... ... ...

@RudiC

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

Smilie
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.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move matching file to folder in same directory

The below bash executes but nothing is copied. I am trying to cp or mv the matching .pdf to the corresponding folder. There will always be a matching .pdf found but the number of folders may vary. The portion in red is what is used to match the .pdf--- variable $pdf to the folder--- variable... (11 Replies)
Discussion started by: cmccabe
11 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

4. Shell Programming and Scripting

Rename files from multiple directories along with directory indicator

Hi, Friends, i have a requirement where i need to rename my files residing in multiple sub directories and move them to one different directory along with some kind of directory indicator. For eg: test--is my parent directory and it has many files such as a1.txt a2.txt a3.txt ... (5 Replies)
Discussion started by: gnnsprapa
5 Replies

5. Shell Programming and Scripting

Move files from Space Folder to other folder

I want to move a folder with spaces from one folder to another. I have two folders like this, 1).RT_032-222 -4444-01/ 2). RT_032-555 -7777-01/ I want to move files from 2 to 1 through shell script.Here I want to assign this like a user defined variable like as Source branch... (2 Replies)
Discussion started by: kannansoft1985
2 Replies

6. Solaris

Move files to another folder base on DU

Hi, I want to move files like *.txt to another filesystem on the same server only when the disk usage reaches 80% or more. But need to keep the latest 5 files. After that delete from the original. How to proceed? Please help Gav... (5 Replies)
Discussion started by: Gavisht
5 Replies

7. Shell Programming and Scripting

Move only files to a folder

I want to move all the files inside a directory to another directory which is inside that directory. Please help. Note: I want to move only the files. Note the folders. Thanks in advance. (4 Replies)
Discussion started by: brnl_basu
4 Replies

8. UNIX and Linux Applications

Move Files From One Folder To Another In UNIX

There are around 13 files in folder1.I need to move these files to another folder folder2,one file at a time, after checking whether a file exists in another folder folder3. If a file exists in folder3, we should not move files from folder1 to folder2. If there are no files in folder3, we need... (1 Reply)
Discussion started by: Jassz
1 Replies

9. Shell Programming and Scripting

move files to some folder

Hello folk, I want to move some *.jpg and *.JPG to some folder but i want move from current path not from subdirectories, wants to move 200 days old file. it will go in /dir/aa/target/*.jpg|*.JPG but not go inside /dir/aa/target/other-directories, Plese help (2 Replies)
Discussion started by: learnbash
2 Replies

10. UNIX for Dummies Questions & Answers

move files from folder thats are not empty

Hi, I would like to write a shell script that moves files from one folder to another without retrieving the error 'can not find file or folder' when the folder is empty. Any ideas, Thx in advance, Steven. (8 Replies)
Discussion started by: Steven
8 Replies
Login or Register to Ask a Question