2

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.

  • 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
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.