How do you defrag Linux?

I am not sure how often fragmentation happens on Linux but I was recommended by someone (I work with) to defrag it. He is an iOS user though so I am not sure why he’d recommend it. I am getting mixed information doing my own research. Some say it isn’t needed, others say you can do it if you want. I am wondering how to actually do it though. Does anyone know how to defrag Linux?

1 Like

Interesting question. I searched and probably read sites you did. A program called e2fsck (not sure how it differs from plain old fsck) reports non contiguous blocks, so you can get an idea how bad your problem is. This page shows the syntax for e2fsck.

I won’t recommend a defrag program, as I haven’t ever needed one, and I know nothing more than today’s reading. The page I linked provides details on how to defrag, but I recommend studying up; low level operations like this are definitely “measure twice and cut once” operations.

2 Likes

I would agree. I’ve never completed a defrag in Linux, ever. :+1::grin:

2 Likes

I would say buying a cheap SSD is the solution. :stuck_out_tongue_winking_eye: Defrag is more a windows thing. If you have an SSD installed you don’t need to defrag. Instead, you will add TRIM.

See this article which I need to update but most is still valid:

To answer the question, for Linux to defrag you refer to some of these links:

2 Likes

Defragging Linux is almost never needed. Only in very niche scenarios would you ever want to do this.

As mentioned, it is more of a Windows thing and something most (99%) Linux users do not have to concern themselves with.

You have the information on why it isn’t needed and more. If you have any other questions, just ask here. I am sure someone can help.

1 Like