Move and copy files in Terminal
In Terminal, you can move and copy files locally or remotely using the mv
, cp
, and scp
command-line tools.
Note: It’s easier to move and copy files using the Finder. For more information, see Organize files in folders.
Move a file or folder locally
To move files or folders from one location to another on the same computer, use the
mv
tool. Themv
tool moves the file or folder from its old location and puts it in the new location.For example, to move a file from your Downloads folder to a Work folder in your Documents folder:
mv ~/Downloads/MyFile.txt ~/Documents/Work/MyFile.txt
You can also change the name of the file as it’s moved:
mv ~/Downloads/MyFile.txt ~/Documents/Work/NewFileName.txt
For more information about the mv
tool, see its man page.
Copy a file or folder locally
To make a copy of a file, use the
cp
tool.For example, to copy a folder named “Expenses” in your Documents folder to another volume named “Data”:
cp -R ~/Documents/Expenses /Volumes/Data/Expenses
The
-R
flag causescp
to copy the folder and its contents. Note that the folder name does not end with a slash, which would change howcp
copies the folder.
For more information about the cp
tool, see its man page.
Copy a file or folder remotely
To copy a file or folder to or from a remote computer, use the
scp
tool.scp
uses the same underlying protocols asssh
.For example, to copy a compressed file from your home folder to another user’s home folder on a remote server:
scp -E ~/ImportantPapers.tgz username@remoteserver.com:/Users/username/Desktop/ImportantPapers.tgz
You’re prompted for the user’s password.
The
-E
flag preserves extended attributes, resource forks, and ACL information.The
-r
flag, which isn’t used in this example, causesscp
to copy a folder and its contents.
For more information about the scp
tool, see its man page.