What is the best way to defragment a FAT filesystem when running Linux/Unix (on usb stick for instance)?
You can check whether a file is fragmented or not using the
That way you could filter out the files that aren't fragmented, and do the copy/copy back only for already fragmented files. That should save you some time. However be aware that there is no guarantee the new file layout will be better than the old one.
The best way is to ignore file fragmentation altogether. Especially on a USB stick it hardly matters, only wastes write cycles, and unlike HDDs, there are no movable parts and thus not much of a penalty due to fragmentation.
Defragmentation should only be necessary if something funny happened that caused files to fragment in a very extreme way. For example torrent clients that download file contents in random order without preallocating. But unless FAT started supporting sparse files at some point that's not even an issue there, as preallocating is mandatory on such a FS.
|show 1 more comment|