Wednesday, May 1, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 3943  / 3 Years ago, wed, september 22, 2021, 9:42:58

I am trying to write a script that will search a directory for a folder, and move the folders contents one directory up from their location. this is what i have so far:



find ./localFolders -name 'file' -type d -exec mv {}/* .. ;


I think my problem lies in the destination directory of ... perhaps I am expressing this wrong?



Any help is useful.



*edit**



to simplify this ill go into more info



I am with an organization that it attempting to move from MS Exchange to Zimbra. As part of our migration we have found great utilities that transfer mailboxes but transferring PST files to Zimbra usable format is proving challenging.



I have found some solutions though to make a long story short, I have been able to spin out pst files to a usable format with one exception –



instead of putting the mail in that folder a sub directory is created called “mbox” presumably resembling the mbox file that the .eml files are being broken out from. Because each user is different and uses different folder structures from other users, each directory is unknown until the script runs. Additionally the contents of the mbox folder are also unique.



Because the folder named mbox is the only constant in these directories I am trying to use find to locate those folders take that folders contents and move them up one directory, then delete the folder named mbox. Here is the actual command as it appears in my script:



find localFolders -name mbox -type d -exec mv {}/* .. ;


or in the example you just gave:



find localFolders -name mbox -type d -execdir sh -c 'echo mv {}/* ..' ;


I am trying to use the * as a wildcard to select everything in the mbox folder . As best as I can tell it is instead being treated as part of the directory, and not the wildcard as intended



thoughts?


More From » command-line

 Answers
3

How about this?



find ./localFolders -name 'file' -type d -execdir bash -c 'mv -vnt . -- "$0"/*' {} ; -prune


Safe regarding spaces and funny symbols in filenames. Enjoy!


[#30548] Wednesday, September 22, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
landarre

Total Points: 254
Total Questions: 96
Total Answers: 109

Location: Burundi
Member since Sun, Apr 16, 2023
1 Year ago
;