The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 07-15-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Here's one way. Take out the prints when you have finished testing. The tail +2 is to skip the total blocks displayed by ls -l. This will not work if any of the filenames contain spaces.

Code:
i=0
split=1000
ls -l | tail +2 | sort -rn -k 5,5 | awk '{print $NF}' | while read f
do
        (( i%${split}==0 )) && print mkdir subdir$(( i/${split} ))
        print mv $f subdir$(( i/${split} ))
        (( i=i+1 ))
done