0

I have the following folder structure.

Service
|
-- App1
  |
  --- bin
  |
  --- file1
  |
  --- file2
|
--App2
  |
  --- bin
  |
  --- file1
  |
  --- file2
  |
  --- file3
|
--App3
  |
  --- bin
  |
  --- file1
  |
  --- file2

I'm looking to move files only from the root of App folders to their corresponding bin folders whilst preserving GIT history. So the end result should be:

Service
|
-- App1
  |
  --- bin
     |
      --- file1
     |
      --- file2
|
--App2
  |
  --- bin
     |
      --- file1
     |
      --- file2
     |
      --- file3
|
--App3
  |
  --- bin
     |
      --- file1
     |
      --- file2

I attempted the following...

#!/bin/bash

dir1="/c/Service"

subs=`ls $dir1`

for i in $subs; do
  git mv $dir1/$i/* $dir1/$i/bin/
done

...but see the following errors:

fatal: can not move directory into itself

fatal: Invalid path '/c': No such file or directory

Any help appreciated.

3
  • Path /c:? What operating system are you using?
    – terdon
    Jul 29 at 16:46
  • So your command runs "git mv /c/Service/App1/* /c/Service/App1/bin" and the "*" will include "bin". You need to get rid of the bin. You could do the move in 2 steps, move first into ElEpHaNt or another name that doesn't exist and then move that to bin. What do you want to do with things already in "bin"?
    – icarus
    Jul 29 at 16:49
  • The operating system is Windows where I have Git for Windows installed. The "bin" folder is empty for all Apps.
    – Confounder
    Jul 30 at 20:33

1 Answer 1

0

From the parent of the Service directory, you can do:

$ for file in Service/*/*; do 
    if [[ -f "$file" ]]; then 
        echo mv "$file" "$(dirname -- "$file")/bin"
    fi
 done
mv Service/App1/file1 Service/App1/bin
mv Service/App1/file2 Service/App1/bin
mv Service/App2/file1 Service/App2/bin
mv Service/App2/file2 Service/App2/bin
mv Service/App2/file3 Service/App2/bin
mv Service/App3/file1 Service/App3/bin
mv Service/App3/file2 Service/App3/bin

If that looks correct, remove the echo and run it again to actually move the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.