如何通过命令行删除/ bin目录中的二进制文件?

时间:2018-02-15 15:52:49

标签: go

我在go install中运行命令$HOME/go/src/hello/,该二进制文件在目录$HOME/go/bin中获取,然后运行go clean,但二进制文件不会删除。

如何通过命令行删除/ bin目录中的二进制文件?

输出go env

GOARCH="amd64"
GOBIN="/home/stavanger/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/stavanger/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build610113564=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

.zshrc

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export GOBIN=$HOME/go/bin

1 个答案:

答案 0 :(得分:2)

  

-i标志导致clean删除相应的已安装存档   或二进制(什么['go build'或]'去安装'会创建)。

试试go clean -i旗帜?

$ go help clean
usage: go clean [-i] [-r] [-n] [-x] [-cache] [-testcache] [build flags] [packages]

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.

Specifically, 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.go     old gotest file, left from Makefiles
    test.out         old test log, left from Makefiles
    build.out        old test log, left from Makefiles
    *.[568ao]        object files, left from Makefiles

    DIR(.exe)        from go build
    DIR.test(.exe)   from go test -c
    MAINFILE(.exe)   from go build MAINFILE.go
    *.so             from SWIG

In the list, DIR represents the final path element of the
directory, and MAINFILE is the base name of any Go source
file in the directory that is not included when building
the package.

The -i flag causes clean to remove the corresponding installed
archive or binary (what 'go install' would create).

The -n flag causes clean to print the remove commands it would execute,
but not run them.

The -r flag causes clean to be applied recursively to all the
dependencies of the packages named by the import paths.

The -x flag causes clean to print remove commands as it executes them.

The -cache flag causes clean to remove the entire go build cache.

The -testcache flag causes clean to expire all test results in the
go build cache.

For more about build flags, see 'go help build'.

For more about specifying packages, see 'go help packages'.
$
  

Command go

     

Remove object files

     

用法:

go clean [-i] [-r] [-n] [-x] [build flags] [packages]
     

Clean从包源目录中删除目标文件。去吧   命令在临时目录中构建大多数对象,所以去干净就是   主要关注其他工具或手动留下的目标文件   调用go build。

     

具体来说,clean会从每个文件中删除以下文件   与导入路径对应的源目录:

_obj/            old object directory, left from Makefiles
_test/           old test directory, left from Makefiles
_testmain.go     old gotest file, left from Makefiles
test.out         old test log, left from Makefiles
build.out        old test log, left from Makefiles
*.[568ao]        object files, left from Makefiles

DIR(.exe)        from go build
DIR.test(.exe)   from go test -c
MAINFILE(.exe)   from go build MAINFILE.go
*.so             from SWIG
     

在列表中,DIR表示目录的最终路径元素,   和MAINFILE是目录中任何Go源文件的基本名称   构建包时不包括在内。

     

-i标志导致clean删除相应的已安装存档   或者二进制('install install'会创建什么)。

     

-n标志会导致clean打印出删除命令   执行,但不运行它们。

     

-r标志导致clean以递归方式应用于所有   导入路径命名的包的依赖关系。

     

-x标志导致clean在执行时删除命令。

     

有关构建标志的更多信息,请参阅“go help build”。

     

有关指定包的详细信息,请参阅“go help packages”。