The command line—that hidden world of code behind your Mac’s pretty OS X face—sometimes offers a quicker way to do everyday tasks. You’ve learned how to navigate files and folders with the command line and get help when you need it from man pages. Today, 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.
Why bother with the command line?
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:
You can copy or move files from one location to another without opening windows in the Finder.
You can copy or move files that are hidden in the Finder; these files, which can contain settings for certain apps or parts of OS X, contain a dot (.) before their names, and the Finder doesn’t show them.
You can copy or move multiple files using wildcards.
You can rename a file quickly.
If you’ve lost access to the Finder because your Mac is on the blink, you might be able to use the command line to troubleshoot the problem.
The difference between copying and moving files
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.
To read this article in full or to leave a comment, please click here