3

I have a very basic idea:

I would like to defragment files in size less than 100MB only in ext4 filesystem.

Since there is no option for that in the defragmentation tool (e4defrag), any ideas how I could achieve that?

I know only how to find those files:

find / -type f -size -100M

Reason for such action:

I had a system with 99.x% of the fs occupied, I freed the space now, leaving many files fragmented.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
  • First check to see if de-fragmentation needs doing. `ext` file systems don't get as fragmented as `fat` or `ntfs`. About the only scenario that causes excessive fragmentation slowly appending to a file (and even this is reduced by `ext`. So if your partition is mostly log files, then it may fragment. To mitigate this, as part of log rotation, zip the older logs. This will, as well as saving space, de-frag the files. – ctrl-alt-delor Jan 24 '18 at 10:14

1 Answers1

4

I was a hair away from a solution:

sudo find / -xdev -type f -size -100M -exec e4defrag {} +

Notes:

  • the -xdev argument as man page says:

    Don't descend directories on other filesystems.

    This means it will not process any other filesystems like tmpfs (/tmp) etc., see mount -v for all you have mounted.

Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309