0

My directory is like this:

/Users/dave/Desktop/test/untitled_folder_0001/vol_0000
/Users/dave/Desktop/test/untitled_folder_0001/rs

/Users/dave/Desktop/test/untitled_folder_0001/t1
/Users/dave/Desktop/test/untitled_folder_0001/str

I want to move all vol_0000 to rs and t1 to str in 1500~ untitled_folder_**** inside test in a shell script if possible.

I already tried many times, but got no where. im writing this anew because i was not able to get help before. Here is the previous thread! If this was answered i will delete that one for redundancy.

Moving files from one subdirectory to another

Community
  • 1
  • 1
tsumaranaina
  • 185
  • 1
  • 11
  • Do you want get it done using shell script? If so then mention in question in question and also mention what you have tried so far ? – Mahendra Feb 26 '16 at 06:48
  • I added a link to what i have tried! – tsumaranaina Feb 26 '16 at 07:02
  • So you want to move all the files named `vol_`* from `untitled_folder_0001` to the `rs` subfolder of `untitled_folder_00001` (which is a different folder from the first one, with an extra 0 in its name)? Or is `vol_0000` a subfolder whose contents you want to move to that folder? And you also want to move all the files from `t1` in some other folder to a directory named `str` that's in the same parent folder as `t1`? – Mark Reed Feb 27 '16 at 01:15
  • 1
    Possible duplicate of [Moving files from one subdirectory to another](http://stackoverflow.com/questions/35598698/moving-files-from-one-subdirectory-to-another) – Elliott Frisch Feb 27 '16 at 01:15
  • @Mark Reed, thank you for pointing this out! I fixed it, in the Q again! I have almost 1500+ folders inside test (untitled_folder_0001 ~ untitled_folder_1678). Each contains the above 2 files and 2 folders. I want to put the files in their designated folders! – tsumaranaina Feb 27 '16 at 01:18
  • @ElliottFrisch Please check the note at the end of this Q! – tsumaranaina Feb 27 '16 at 01:22

1 Answers1

2

Easiest way is probably with a loop.

for f in /Users/dave/Desktop/test/untitled_folder_*; do
  mv "$f"/vol_0000 "$f"/rs # move everything from `vol_0000` into `rs`
  mv "$f"/t1 "$f"/str
done

... assuming I've understood the goal correctly.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • Output mv: rename /Users/dave/Desktop/test/untitled_folder_1/vol_0000/* to /Users/dave/Desktop/test/untitled_folder_1/rs/*: Not a directory mv: rename /Users/dave/Desktop/test/untitled_folder_1/t1/* to /Users/dave/Desktop/test/untitled_folder_1/str*: Not a directory mv: rename /Users/dave/Desktop/test/untitled_folder_2/vol_0000/* to /Users/dave/Desktop/test/untitled_folder_2/rs*: Not a directory mv: rename /Users/dave/Desktop/test/untitled_folder_2/t1/* to /Users/dave/Desktop/test/untitled_folder_2/str*: Not a directory ... – tsumaranaina Feb 27 '16 at 01:45
  • Why are you putting `*`s on the destination names? – Mark Reed Feb 27 '16 at 01:49
  • Sorry it seems that i am not able to explain my directory properly. each folder untitled_folder_0001 to untitled_folder_**** contains (/Users/dave/Desktop/test/untitled_folder_0001/), these four items vol_0000 (file) rs (folder) t1 (file) str (folder) I want to move col to rs and t1 to str in all the untitled_folder_**** that i have! – tsumaranaina Feb 27 '16 at 01:49
  • I copied the code exactly as you put it! This is exactly what i did! for f in /Users/dave/Desktop/test/untitled_folder_*; do mv "$f"/vol_0000/* "$f"/rs # move everything from `vol_0000` into `rs` mv "$f"/t1/* "$f"/str done – tsumaranaina Feb 27 '16 at 01:53
  • Oh, vol_0000 and t1 are *files*,not subfolders. OK, see edited answer. – Mark Reed Feb 27 '16 at 02:04
  • will do once i have 15 reputations! Sorry, just started with this! – tsumaranaina Feb 28 '16 at 03:49