Operations 19 min read

Essential Linux Debugging Commands Every Developer Should Know

This guide introduces a collection of classic Linux debugging utilities—including file, ldd, ltrace, hexdump, strings, readelf, objdump, strace, nm, and gdb—explaining their purpose, typical usage, and providing concrete command‑line examples to help developers troubleshoot binaries and libraries efficiently.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Essential Linux Debugging Commands Every Developer Should Know

Linux provides a rich set of command‑line tools for inspecting and debugging binaries, shared libraries, and system calls. Mastering these utilities can dramatically improve troubleshooting efficiency.

#file

The file command reports the exact type of a file, such as ELF executable, script, or archive.

#ldd

ldd

lists the shared libraries required by a dynamically linked executable, showing each library’s path.

#ltrace

ltrace

traces library function calls made by a program, displaying the called function, arguments, and return values. Example options are listed below:

-a   Align output columns
-c   Count time and calls, print summary on exit
-C   Decode kernel‑level names to user‑level
-d   Print debugging information
-e   Change traced events
-f   Follow child processes
-h   Show help
-i   Print instruction pointer on library calls
-l   Trace only calls from a specific library
-n, --indent=NR   Indent each call level by NR spaces
-o, --output=file   Redirect output to a file
-p PID   Attach to process with PID
-r   Print relative timestamps
-s STRLEN   Limit printed string length
-t, -tt, -ttt   Print timestamps
-T   Show time spent in each call
-u USERNAME   Run command as specified user
-V, --version   Show version
-x NAME   Treat NAME as a library subroutine

Sample usage:

weiqifa0@weiqifa-System-Product-Name:~$ ltrace ls
strrchr("ls", "/")                         = nil
setlocale(LC_ALL, "")                        = "zh_CN.UTF-8"
... (output truncated for brevity)

#hexdump

hexdump

displays the hexadecimal representation of a file’s contents, useful for low‑level inspection.

weiqifa0@weiqifa-System-Product-Name:~$ hexdump /bin/ls | head
0000000 457f 464c 0102 0001 0000 0000 0000 0000
0000010 0003 003e 0001 0000 5850 0000 0000 0000
... (more lines omitted)

#strings

strings

extracts printable strings from binary files, helping to discover embedded text.

#readelf

readelf

examines ELF‑format files (executables, shared objects, static libraries) and prints detailed header and section information. The examples target an Android‑compiled .so file.

#objdump

objdump

disassembles object files, showing sections, symbols, and machine code.

# Example: disassemble a simple program
weiqifa0@weiqifa-System-Product-Name:~/c$ cat 1.c
#include "stdio.h"

int main(void) {
    printf("hello,world
");
    return 0;
}
weiqifa0@weiqifa-System-Product-Name:~/c$ gcc 1.c -o 1.o
weiqifa0@weiqifa-System-Product-Name:~/c$ objdump -h 1.o

1.o:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
 0 .interp       0000001c  00000000000002a8  ...
 ... (section list continues)

#strace

strace

traces system calls made by a program, printing each call with its arguments and return value.

weiqifa0@weiqifa-System-Product-Name:~/c$ strace /bin/ls
execve("/bin/ls", ["/bin/ls"], 0x7ffdb4868620 /* 23 vars */) = 0
brk(NULL)                               = 0x55ebe6544000
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
... (output continues)

#nm

nm

lists symbols from object files, showing addresses, symbol types, and names, which is useful for understanding linking.

weiqifa0@weiqifa-System-Product-Name:~/c$ nm 1.o
0000000000004010 B __bss_start
0000000000004010 b completed.7963
                 w __cxa_finalize@@GLIBC_2.2.5
0000000000004000 D __data_start
... (more symbols)

#gdb

gdb

is the GNU Debugger, the de‑facto debugging tool on Linux. It allows setting breakpoints, inspecting memory, and stepping through code.

weiqifa0@weiqifa-System-Product-Name:~/c$ gdb 1
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0
...
(gdb) list
1       #include "stdio.h"
2
3       int main(void)
4       {
5           printf("hello,world
");
6           return (0);
7       }
(gdb) b main
Breakpoint 1 at 0x1139: file 1.c, line 5.
(gdb) run
Starting program: /home/weiqifa0/c/1

Breakpoint 1, main () at 1.c:5
5           printf("hello,world
");
(gdb)

These commands together form a practical toolbox for developers working on Linux systems, enabling them to identify file types, resolve library dependencies, trace function and system calls, inspect binary contents, and debug source code.

DebuggingGDBstracecommand-lineltracesystem-tools
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.