ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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..)
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. 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.
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.
In your first post you only mentioned one target directory which implied that you had a single target. This explanation is, I hope, a more correct description of your actual problem.
So, a few other questions:
Is the 20 directories a fixed number? If the top folder contains N folders and you have P people to process folders, do you, instead, want to divide the N folders as equally as possible among the P people?
Are all the people "processing" folders equally capable? If not, can they be ranked or grouped by ability?
Are all folders equally hard to "process?" If not, can the difficulty of processing a folder be automatically (i.e., by computer) estimated before processing? If so, would that estimate be a numerical score or just a rank (e.g.: Trivial, Easy, Average, Hard, or Impossible)?
Should the factors listed in items 2 and 3 be used when assigning folders to people?
My point here is that, when asking for help, it's best to describe the real problem you want solved rather then asking for help with one possible solution.
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:
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.
Yes, a little TINY bit of perl, and I've gotten fairly good with bash scripting since. The problem is, I think I would also need to read lines to complete this with those command, wouldn't I?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.