2

So, my disk is a mess. First I need to mention that it is a NTFS filesystem. So what I want to do is to completely defragment the disk. I want it so that after defragmenting I have continuous empty space left after the last data sector. Is this possible? I was told it is.

1 Answers1

1
find ~ -maxdepth 20 -type f -size -16M -print > t; for ((i=$(wc -l < t); i>0; i--)) do a=$(sed -n ${i}p < t); mv "$a" /dev/shm/d; mv /dev/shm/d "$a"; echo $i; done; echo DONE; rm t

for flash drives ( and external hard drives ), replace the "~" in "find ~ -maxdepth" with the location of the drive.

example:

find /dev/sdb1 -maxdepth 20 -type f -size -16M -print > t; for ((i=$(wc -l < t); i>0; i--)) do a=$(sed -n ${i}p < t); mv "$a" /dev/shm/d; mv /dev/shm/d "$a"; echo $i; done; echo DONE; rm t

this works in most cases. the script basically re-copies most data under 16 mb from the drive back to the drive. it works because most filesystems (including fat 32 ) will always try to keep new data contiguous when it is saved.

This is designed to defrag the ~/ directory. If you are really looking to get the job done, I suggest you try defraging the disk using a windows computer/program.

Wine maybe too?

Max Kulik
  • 538