Start United States USA — software Master the macOS command line: How to copy and move files through...

Master the macOS command line: How to copy and move files through Terminal

483
0
TEILEN

The command line—that hidden world of code behind your Mac’s pretty face—sometimes offers a quicker way to do everyday tasks, plus it’s just a cool …
The command line—that hidden world of code behind your Mac’s pretty face—sometimes offers a quicker way to do everyday tasks, plus it’s just a cool way to establish your tech cred. You’ve learned how to navigate files and folders as well as delete files and folders with the command line and get help when you need it from man pages. Here, I’ll show you how to copy and move files, common operations that often come in handy. I’ll also show you how to create directories (that’s Unix-speak for folders), so you can move files to new places. It’s certainly easy to copy and move files in the Finder, but there are a number of reasons why you might want to do this from the command line instead: If you’re in the Finder, and you drag a file from, say, your Desktop to your Documents folder, or any other folder on the same disk or volume, you move the file. The file is no longer on the Desktop, and is found only in the Documents folder. However, if you drag a file from your Desktop to an external hard disk, you’ll see that the file remains in its original location; this file has been copied. (You may know that you can copy a file in the Finder, even on the same hard disk, by holding down the Option key when you drag it.) The same is the case from the command line. There are two commands for moving and copying: mv and cp. The first does the same as dragging a file to a new location on the same hard disk. The second does what an Option-drag does, or what happens when you drag a file to a different disk or volume. Copying files with the cp command is simple. First, launch Terminal (in your /Applications/Utilities folder). Then, use the following syntax to create your command: cp source destination For example, to copy a file named MyFile.rtf from your Desktop folder to your Documents folder, you would type in the following command in Terminal and then press Return: cp ~/Desktop/MyFile.

Continue reading...