Skip to main content

Command Palette

Search for a command to run...

What is /lib in linux

Published
β€’2 min readβ€’View as Markdown
What is  /lib in linux
I

I am a self taught Linux System Engineer with a strong background in Networking and Radio frequency technologies. I am currently working as a Cloud Support Engineer (Linux) and I love working with Open Source.

βœ… What is /lib in Linux?

/lib stands for libraries.

It contains essential shared libraries and kernel modules needed by the binaries in /bin and /sbin.

Think of it as the supporting code that these core commands need to run.


πŸ“¦ What kind of information does /lib contain?

Primarily:

1️⃣ Shared Libraries (.so files)

Equivalent to Windows DLLs.

Provide reusable code for multiple programs.

Example: /lib/libc.so.6 (standard C library).

2️⃣ Kernel Modules

Optional parts of the Linux kernel that can be loaded/unloaded at runtime.

Example: /lib/modules/$(uname -r)/.


βš™οΈ Real-world analogy

Imagine /bin/ls is a program you want to run.

It’s a tiny front-end that calls code in shared libraries.

/lib holds those libraries so ls doesn’t have to include all the code itself.


πŸ—‚οΈ Typical contents of /lib

βœ… Shared Libraries

libc.so.* – Standard C library (essential for almost every command)

ld-linux.so.* – Dynamic linker/loader

libm.so.* – Math library

βœ… Kernel Modules

/lib/modules//

Drivers for filesystems, networking, hardware, etc.

βœ… Systemd libraries (in some distros)

Parts of the init system.


🧭 When is /lib used in real life?

πŸ‘‰ Booting and recovery

Essential libraries must be available very early in boot.

Used by statically minimal environments (like initramfs).

πŸ‘‰ Running system commands

/bin/ls, /bin/cp, /sbin/ifconfig – all dynamically linked to libraries in /lib.

Without /lib, these basic tools wouldn’t work.

πŸ‘‰ Loading kernel modules

Adding support for new hardware on the fly.

E.g., modprobe loads drivers from /lib/modules.


πŸ”Ž Example: Listing /lib

ls /lib

You might see:

ld-linux.so.2 libc.so.6 libm.so.6 modules/ systemd/


βœ… Difference with /usr/lib

/lib = essential libraries needed to boot and run /bin and /sbin commands.

/usr/lib = non-essential libraries for things in /usr/bin and /usr/sbin.

Example:

Directory Purpose When used

/lib Critical libraries for booting/system Early boot, rescue mode /usr/lib Extra libraries for installed software Desktop apps, user-level programs


βœ… TL;DR

πŸ“Œ /lib contains critical shared libraries and kernel modules. πŸ“Œ Supports essential system binaries in /bin and /sbin. πŸ“Œ Crucial for booting, recovery, and hardware support.

More from this blog

B

Being a Linux Administrator

14 posts

This page and publication is about knowledge and resource sharing. The main topics covered here are pertaining to Linux and Open Source as well as Cloud computing.