Home / Mac / Master command line: Copy and move files on Mac

Master command line: Copy and move files on Mac



The command line – the world of hidden codes behind the nice face of your Mac – sometimes provides a faster way to do everyday tasks, plus it’s just a cool way to establish your technical cred. You have 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 will show you how to copy and move files, common operations that are often useful. I also show you how to create directories (it’s Unix-speak for folders) so you can move files to new locations.

Why bother with the command line?

Copying and moving files in the Finder is certainly easy, but there are several reasons why you might want to do this from the command line instead:

  • You can copy or move files from one place to another without opening Finder windows.
  • You can copy or move files hidden in the Finder. These files, which may contain settings for specific apps or parts of your Mac, contain a dot (.) In front of their names, and the Finder does not display them.
  • You can copy or move several files using wildcards.
  • You can rename a file quickly.
  • If you have lost access to the Finder because your Mac is blinking, you may be able to use the command line to troubleshoot the issue.

The difference between copying and moving files

If you are in the Finder and you drag a file from, for example, the desktop to the Documents folder or any other folder on the same disk or volume, move the file. The file is no longer on the desktop and can only be found in the Documents folder. However, if you drag a file from the desktop to an external hard drive, you will 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 thing as dragging a file to a new location on the same hard drive; the other does what an Option drag does, or what happens when you drag a file to another disk or volume.

How to copy files

Copy files with cp the command is simple. First start Terminal (in the folder / Programs / Tools). Then use the following syntax to create your command:

cp source destination

For example, to copy a file named MyFile.rtf from the desktop folder to the Documents folder, type the following command in Terminal, and then press Enter:

cp ~/Desktop/MyFile.rtf ~/Documents

Note: When you buy something after clicking on links in our articles, we can earn a small commission. Read our affiliate link policy for more information.


Source link