How to copy a file by terminal

I need to use the terminal to copy a file from the Documents directory to the /usr/local/go/src or /Users/giorgio/go/src.

I can't recognise the directories from the terminal. I don't even find the file I can see in Documents by the finder.


I am new to using terminal, can someone help me?


Thank you

Giorgio

MacBook Pro 15”, macOS 10.15

Posted on Feb 26, 2020 8:48 PM

Reply
5 replies

Feb 26, 2020 9:05 PM in response to giorgio226

Don't use the Terminal if you aren't familiar. You do not need to use it in order to make the transfer. Start be finding the file you want to transfer in the Documents folder. Select the file and press Command-C to Copy. Now, from the Finder's Go menu select Go to Folder. In the field that appears enter the path to the target folder, "/usr/local/go/src/", or "/Users/giorgio/go/src/". When the folder is opened in the Finder press Command-V to Paste the file in the open folder.


FWIW, I checked my system and did not find a /usr/local/go/src/ folder, so it must only exist on your system as a result of some third-party software you have installed.

Feb 27, 2020 10:05 AM in response to giorgio226

I am not familiar with the language nor its required installation. I don't know how you are using TextEdit but be sure you are in Plain Text Mode. Also, be sure to add the required extent, ".go" in place of the default ".txt". Perhaps, the compiler did not find a file with the desired extent.


I think you should ask the support for the language, namely, the developer. The directories required do not exist as part of macOS, therefore, you need to create them unless the language installer created them. You need to check if they are there, and, if not, create them.

Feb 26, 2020 9:34 PM in response to Kappy

Thank you, but I still can't do what I would like. Now I am probably out of the topic, but you helped me so maybe you know the answer to this different question.

I am starting with the go language and to check if installed properly I have to do this:


Create a file named hello.go that looks like:

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

Then build it with the go tool:

$ go build hello.go

The command above will build an executable named hello in the current directory alongside your source code. Execute it to see the greeting:

$ ./hello
hello, world

I created the file using textedit but after giving the build command in the terminal I had an error message

MacBook-Pro-di-Giorgio:~ giorgio$ go build hello.go


can't load package: package hello.go: cannot find package "hello.go" in any of:


/usr/local/go/src/hello.go (from $GOROOT)


/Users/giorgio/go/src/hello.go (from $GOPATH)


I was thinking I should only place the file in the right folder but it didn't work because I had again the same error message.

I only installed the go package and added in the /etc/profile the line
 export PATH=$PATH:/usr/local/go/bin

I added the same line in the $HOME/.profile .

Can you help me?

Feb 27, 2020 11:08 PM in response to giorgio226

giorgio226 wrote:

Execute it to see the greeting:
$ ./hello
hello, world
I created the file using textedit but after giving the build command in the terminal I had an error message
MacBook-Pro-di-Giorgio:~ giorgio$ go build hello.go

can't load package: package hello.go: cannot find package "hello.go" in any of:

/usr/local/go/src/hello.go (from $GOROOT)

/Users/giorgio/go/src/hello.go (from $GOPATH)

You are trying to execute the build from a location that does not exist in the $GOROOT or $GOPATH according to the error message. This could just indicate an incorrect file name or extension as @Kappy mentions. macOS doesn't make it easy with all the "user friendly" default settings. You may want to use another editor which is more coding friendly. In the mean time you can use the command line editor "nano". Use the terminal to verify the name and extension of the source file you created.


If the extension is not the issue, then you should probably review the Go documentation and ask for help from a Go programming community.


Another possibility if you are using Catalina is that Catalina now defaults to using zsh instead of Bash for the shell. It is possible some setup and configuration instructions may not have been fully updated to incorporate zsh.


I would also suggest you either create a VM or use an older computer to get familiar with the command line so you do not wreck your main OS at least while you are learning the command line and programming. To properly test out "finished" code you should test it on a regular & clean system without any developer tools installed.


Good luck.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to copy a file by terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.