How to use the go clean command line
Created
Clean removes object files from package source directories. The go command builds most objects in a temporary directory, so go clean is mainly concerned with object files left by other tools or by manual invocations of go build.
clean
go clean
go mod clean cache
go clean --modcache
The go clean Commands and Options
Usage:
go clean [clean flags] [build flags] [packages]
Clean flags:
-iThe -i flag causes clean to remove the corresponding installed archive or binary (what 'go install' would create).-nThe -n flag causes clean to print the remove commands it would execute, but not run them.-rThe -r flag causes clean to be applied recursively to all the dependencies of the packages named by the import paths.-xThe -x flag causes clean to print remove commands as it executes them.-cacheThe -cache flag causes clean to remove the entire go build cache.-testcacheThe -testcache flag causes clean to expire all test results in the go build cache.-modcacheThe -modcache flag causes clean to remove the entire module download cache, including unpacked source code of versioned dependencies.
If a package argument is given or the -i or -r flag is set, clean removes the following files from each of the source directories corresponding to the import paths:
_obj/old object directory, left from Makefiles_test/old test directory, left from Makefiles_testmain.goold gotest file, left from Makefilestest.outold test log, left from Makefilesbuild.outold test log, left from Makefiles*.[568ao]object files, left from MakefilesDIR(.exe)from go buildDIR.test(.exe)from go test -cMAINFILE(.exe)from go build MAINFILE.go*.sofrom SWIG