Bash script to select "first x folders"?
Is there a way to have bash "select" 20 folders and move them in a directory? The goal of this script would be to move 20 folders into 1 new folder elsewhere, then repeat until there are no folders left (so the last selected amount will likely be less than 20 folders..)
|
sure, you can use a combination of commands for that in a script, such as: ls, head, mv.
|
For the list of directories, try tree -lfid "path_to_top_directory" > "/tmp/dir_list" or look at the -type option in the findcommand.
But I don't understand why you want to do the move in blocks of 20 directories. :scratch: If the source and target are on the same drive, the move only involves the directories, and no actual data is physically moved. If the target is on a different drive, then each file in each directory is copied one at a time, so you save nothing by moving the data in groups of 20 directories. Bottom line: Why not just mv the top-level directory to the destination? The only complication I could see would be caused by the presence of links defined using relative path notation in the items being moved, although there are options in the mv command that address that issue. |
Thanks for the replies. The data is being "batched" Several people will each take a chunk of files and process them. It's just the way things have been done here for years.
I think you are a bit confused... take this example: I have 40 directories in a folder. I want to create 2 new directories and move 20 of the original 40 into each of those 2 directories. Now those 2 new directories contain 20 files each. |
from last year till now, you have at least have exposure to Perl and shell scripting. what have you got so far? you didn't study any of them at all? a combination of wc , head, mv etc will do the job. you can also do everything in Perl if you want.
|
Quote:
So, a few other questions:
Oh, I just thought of another set of questions: Why group the directories for processing by individuals? Why not just pass the next available unassigned directory to a processor when they finish processing one? Is there, in fact, any point in creating the groups of directories? |
1. Yes. I always want to move the initial sets of folders into new folders containing 20 of the original. There could be any amount of initial folders. 365, 521, 50, etc. Does this make sense?
2. This doesn't matter 3. This also doesn't matter Because of the software used and the way this business runs, it just doesn't work that way. This is basically used to split the work, and to keep track of what is and isn't done. Because I'm having difficulty explaining this, I'll try to illustrate it. I will make the example of folders containing 5 folders instead of 20 as I am requiring: /home/abc/files/ABC1 /home/abc/files/ABC2 /home/abc/files/ABC3 /home/abc/files/ABC4 /home/abc/files/ABC5 /home/abc/files/ABC6 /home/abc/files/ABC7 <script runs> ls -laR /home/abc/files2/COMPLETE1 ./ABC1 ./ABC2 ./ABC3 ./ABC4 ./ABC5 /home/abc/files2/COMPLETE2 ./ABC6 ./ABC7 I really hope this makes sense, lol. |
Quote:
|
All times are GMT -5. The time now is 05:46 AM. |