D
D
Danil Trubitsyn2019-03-10 17:41:35
Windows
Danil Trubitsyn, 2019-03-10 17:41:35

How to scatter files into folders in?

In one folder a huge number of files. You need to scatter them into different folders, any, it doesn’t matter. Challenge: avoid having a large pack of files in one directory.
There are operating systems available: ubuntu 16, windfows 10 and mac os.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitsliputsli, 2019-03-10
@ali3412

count=100; i=0; find . -maxdepth 1 -type f | while read f; do n=$[i/c+1]; i=$[i+1]; mkdir -p "$n" && mv "$f" "$n/$f"; done

only files from the current directory are taken and moved to newly created directories (1,2,3, etc.). "count=100" - number of files in each directory

A
Artem @Jump, 2019-03-10
curated by the

How to scatter files into folders?
Elementary.
We read the hash of the file and write it to the folder according to the first characters of the hash.
For example, the hash D41D8CD98F00B204E9800998ECF8427E means we write the file to folder D
As a result, the files will be scattered into sixteen folders with names from 0 to F
Or we will write the file to folder D and subfolder 4.
As a result, the files will be scattered into sixteen folders with names from 0 to F and in each folder will have sixteen subfolders.
Or you can write to the D4 folder, then the files will be scattered over 256 folders.
In general, by the first letters of the hash.
Since the hash entity is pseudo-random, the folder distribution will be quite uniform.
This approach is used in many storage systems.

K
ky0, 2019-03-10
@ky0

bash, loops, mkdir, mv.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question