Jump to content
obi

Split folder linux

Recommended Posts

Posted

Buna. Ma poate ajuta cineva cu urmatoarea problema. Am un folder cu vreo 150.000 de fisiere si vreau sa il impart in mai multe subfoldere. Un script, ceva ? Mersi.

  • Downvote 1
Posted

Parca esti la piata. "Vreau sa cumpar un porc. Cineva ceva?"

Nu stiu cum poti sa te astepti la un raspuns cand pui o asa intrebare.

 

Pe ce criterii vrei sa imparti fisierele in foldere? Dupa nume, extensie, dimensiune, foldere cu un anumit numar de fisiere? etc...

 

Posted

Chiar daca nu meriti, l-am facut mai mult pentru mine(imi place sa invat lucruri noi):

#!/bin/bash
subfolder_prefix="subfolder_" # subfolder prefix
subfolders=6 #number of subfolders
for i in `seq 1 $subfolders`; do
  mkdir "$subfolder_prefix$i" # create the subfolders
done
current_file=1
for i in $(find . -maxdepth 1 -type f -exec basename \{} \; | grep -v script_create_subfolders.sh); do
  # get all files from current directory.
  mv $i $subfolder_prefix$((current_file%subfolders))"/"$i
  current_file=$(( current_file + 1 ))
done

 

Posted
4 minutes ago, kznamst said:

Chiar daca nu meriti, l-am facut mai mult pentru mine(imi place sa invat lucruri noi):


#!/bin/bash
subfolder_prefix="subfolder_" # subfolder prefix
subfolders=6 #number of subfolders
for i in `seq 1 $subfolders`; do
  mkdir "$subfolder_prefix$i" # create the subfolders
done
current_file=1
for i in $(find . -maxdepth 1 -type f -exec basename \{} \; | grep -v script_create_subfolders.sh); do
  # get all files from current directory.
  mv $i $subfolder_prefix$((current_file%subfolders))"/"$i
  current_file=$(( current_file + 1 ))
done

 

Mersi mult. Intre timp m-am descurcat dupa nr. de fisiere.

 

 

i=0;
for f in *;
do
    d=dir_$(printf %03d $((i/1000+1)));
    mkdir -p $d;
    mv "$f" $d;
    let i++;
done

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...