dh_auto_clean - Linux


Overview

dh_auto_clean automatically cleans build directories and Debian source packages in the current directory and all subdirectories. It is primarily used for preparing Debian packages for distribution in a reproducible manner, ensuring that unwanted artifacts do not remain in the final product.

Syntax

dh_auto_clean [options]

Options/Flags

  • -a, --artifacts: Removes all the build directory artifacts, including the debian/ directory.
  • -d, --debbuild: Removes the .deb files created in the build directories.
  • -D, --deep: Removes the .dsc and .tar.xz files created in the build directories.
  • -f, --force-clean: Do not prompt for confirmation before removing files.
  • -p, --print-paths: Prints the paths of the files that would be removed without actually removing them.
  • -r, --remove-version-suffix: Removes the version suffix from the names of the .deb files in the build directories.
  • -v, --verbose: Enables verbose mode, outputting the full paths of files as they are removed.
  • -x, --preserve-build: Do not remove the build directories.

Examples

To automatically clean all build artifacts in the current directory and its subdirectories:

dh_auto_clean

To remove only the .deb files in the build directories:

dh_auto_clean -d

To print the paths of the files that would be removed without actually removing them:

dh_auto_clean -p

Common Issues

One common issue that may occur is that some files may not be removed if they are still open or locked by another process. To resolve this, ensure that all processes using those files are closed before running dh_auto_clean.

Integration

dh_auto_clean can be integrated with other tools such as dh_make to automate the packaging process. For example, the following command can be added to the debian/rules file:

override_dh_auto_clean:
	dh_auto_clean

This will automatically clean the package after it has been built.

Related Commands

  • dh_make: A tool for building Debian packages.
  • dpkg: A tool for managing Debian packages.