0
0
DbtHow-ToBeginner ยท 3 min read

How to Use dbt clean Command to Remove Artifacts

Use the dbt clean command to delete all files in the target and dbt_modules directories of your dbt project. This helps remove compiled files and dependencies safely before a fresh build.
๐Ÿ“

Syntax

The dbt clean command has a simple syntax with no additional arguments needed. It removes the target and dbt_modules folders in your project directory.

  • dbt clean: Deletes the target and dbt_modules directories.
bash
dbt clean
๐Ÿ’ป

Example

This example shows running dbt clean in a dbt project folder. It deletes the target and dbt_modules directories, clearing compiled models and installed packages.

bash
$ dbt clean
Removing directory: target
Removing directory: dbt_modules
Output
Removing directory: target Removing directory: dbt_modules
โš ๏ธ

Common Pitfalls

Common mistakes when using dbt clean include:

  • Running it outside the dbt project folder, so it does nothing.
  • Expecting it to remove source data or logs (it only removes target and dbt_modules folders).
  • Not reinstalling packages after cleaning, which can cause build errors.

Always run dbt deps after dbt clean to reinstall dependencies.

๐Ÿ“Š

Quick Reference

CommandDescription
dbt cleanDeletes target and dbt_modules directories
dbt depsReinstalls packages after cleaning
dbt runBuilds models after cleaning and reinstalling
โœ…

Key Takeaways

Use dbt clean to remove compiled files and installed packages safely.
Always run dbt deps after cleaning to reinstall dependencies.
Run dbt clean inside your dbt project directory.
dbt clean does not delete source data or logs.
Use dbt clean to fix build issues caused by stale files.