You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过命令行删除/bin目录二进制文件及Go编译文件残留问题

Answers to Your Command Line & Go Questions

Hey there, let's break down your two questions with clear, actionable steps:

1. Deleting a Binary File from the /bin Directory

The /bin directory holds critical system binaries, so you'll need elevated privileges to modify it. Here's how to safely delete a file here:

  • First, double-check the exact file path you want to remove (never guess—accidentally deleting a system binary like ls or bash can break your entire system!)
  • Run the rm command with sudo to gain admin access:
    sudo rm /bin/your-target-binary-name
    
    For example, if you added a custom binary named my-tool to /bin, you'd run:
    sudo rm /bin/my-tool
    
  • Critical note: Only delete files you've added or confirmed are non-essential to system operation.

2. Deleting the Go Binary Installed to $HOME/go/bin

The default go clean command only clears local build cache and temporary files from your project directory—it doesn't touch binaries installed to your GOBIN path. Here are two reliable ways to fix this:

Option 1: Directly Delete the Binary with rm

Since you know the file lives in $HOME/go/bin, simply use the rm command:

rm $HOME/go/bin/hello

You can verify the file exists first with:

ls $HOME/go/bin/hello

Option 2: Use go clean -i to Remove Installed Binaries

If you prefer using Go's built-in tools, add the -i flag to go clean—this tells Go to delete the installed binary alongside local build artifacts. Run this from your project directory:

cd $HOME/go/src/hello
go clean -i

This will automatically remove the hello binary from your GOBIN (which is set to $HOME/go/bin in your setup, per your go env and .zshrc config).

Quick clarification: The -i flag stands for "install"—it reverses the go install action by removing the installed executable.


内容的提问来源于stack exchange,提问作者Dmitry S.

火山引擎 最新活动