• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

indent Command Examples

by admin

Indentation in programming refers to the practice of adding spaces or tabs at the beginning of lines of code to visually represent the structure of the code. It is essential for readability and maintainability, particularly in languages like C and C++ where the structure of the code defines its behavior.

The GNU indent tool is a utility used primarily in the C and C++ programming languages to automatically format source code according to a set of style guidelines. This tool allows developers to maintain consistent formatting across their codebase without having to manually adjust every line.

Here’s a more elaborate explanation of how indent works and its features:

  • Whitespace Adjustment: indent can adjust the whitespace in your code, including adding or removing spaces and tabs to ensure proper indentation. This makes the code visually appealing and easier to read.
  • Formatting Options: It provides various options to customize the formatting according to different coding styles or standards. These options include controlling the indentation width, choosing between spaces and tabs, specifying brace placement, and more.
  • Automatic Code Refactoring: indent can automatically reformat your code to adhere to the chosen coding style. This is particularly useful when working on a project with multiple developers who may have different coding preferences.
  • Preserving Comments: The tool preserves comments within the code, ensuring that they remain in the correct location even after formatting. Comments are crucial for understanding the code’s functionality, so preserving them is essential.
  • Batch Processing: indent can process multiple files at once, making it efficient for formatting entire projects or codebases. This saves developers time and effort compared to manually formatting each file individually.
  • Integration with Build Systems: It can be integrated into build systems or automated workflows to ensure consistent code formatting as part of the development process. This helps maintain code quality and readability across the entire codebase.

indent Command Examples

1. Format C/C++ source according to the Linux style guide, automatically back up the original files, and replace with the indented versions:

# indent --linux-style [path/to/source.c] [path/to/another_source.c]

2. Format C/C++ source according to the GNU style, saving the indented version to a different file:

# indent --gnu-style [path/to/source.c] -o [path/to/indented_source.c]

3. Format C/C++ source according to the style of Kernighan & Ritchie (K&R), no tabs, 3 spaces per indent, and wrap lines at 120 characters:

# indent --k-and-r-style --indent-level3 --no-tabs --line-length120 [path/to/source.c] -o [path/to/indented_source.c]

Summary

Overall, indent is a valuable tool for C and C++ developers to maintain consistent coding styles, improve code readability, and streamline the development workflow. By automatically adjusting whitespace and formatting, it helps ensure that the codebase remains clean and understandable, even as it evolves over time.

Filed Under: Linux

Some more articles you might also be interested in …

  1. e2fsck: command not found
  2. adig Command Examples in Linux
  3. elinks Command Examples in Linux
  4. backlight_control Command Examples in Linux
  5. gnome-extension Command Examples in Linux
  6. b2sum Command Examples (Calculate BLAKE2 cryptographic checksums)
  7. “git switch” Command Examples
  8. hwclock Command Examples in Linux
  9. ndctl: command not found
  10. esbuild: JavaScript bundler and minifier built for speed

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright