There are several scripts that listen to different ports. All these scripts are written in the same directory, say / 1 /. At time N (no more than 20 minutes), another script is launched that moves all these files to a directory, say / 2 /, and then their processing starts in directory 2. At the time the files are moved from directory 1 to directory 2, to directory 1 may receive new files. Quite recently, a huge number of files became a problem (several tens of thousands in 20 minutes). The processing does not take much time, the files are stored later in their parameters for 2 weeks, after they are deleted. The start interval of taking files cannot be shortened. Historically everything works that way.
Question:
Is there any way to change directories atomically, that is, empty 2 becomes 1, and directory 1 with files becomes 2. Atomic, of course, not within the processor command, but without prejudice to the system and the operation of the scripts. Maybe there are options to somehow get stuck with inode? Well, I don’t want to rewrite it all. So any advice in this situation is welcome. There is also an idea not to use directory 2. And to process everything from directory 1 at once, but then you probably have to set an exclusive lock on each file in directory 1 for scripts writing these files to it.