How can I defrag an NTFS hard drive from Ubuntu? [duplicate]

Personally I wouldn't bother to defrag the NTFS partition of the HDD since if you install Ubuntu on the spare part it will only use that amount as a hard drive and the rest will not be affected. Then just mount the NTFS on Ubuntu and access the files there.

An ext4 file system doesn't have the problems with empty slots as NTFS or FAT32. The problems with NTFS and FAT32 are that the storage is based on data being put in slots and if a files on fills up 15 slots but are assigned 16 slots then one slot will be empty.

Here is where defrag comes in and moves the data around so that the data is used in each slot and the empty slots are declared as empty instead of used by this and that file. This saves space and makes access times shorter since you don't have to search the whole HDD for a file.

In ext4 files are divided throughout the disk and the fields where the data is stored is linked to the original file, so a file can be stored in row 1 field 2, row 3 field 12, etc.

So moving files around to save space doesn't work in ext4, you will make no more room on the hard drive. it will be just as easy to access files as it was before. This is just an example of the principle, explaining it in detail seemed too complex right now.

Is it possible to defrag an NTFS from Ubuntu
What I've found out by searching on this topic is that there is no program to defrag an NTFS HDD from Ubuntu. The best solution is to:

  1. Mount the HDD under Ubuntu
  2. Copy the files to another HDD
  3. Re-format the HDD (preferably with ext4)
  4. Move back the files

If you don't have another drive I would

  1. Create a ext4 partition on the empty space and move some files to there
  2. Remove those files from the NTFS partition
  3. Resize the NTFS partition to make it smaller
  4. Make the ext4 partition larger

Do this procedure until all files are moved and the NTFS partition is gone.