Specifications

Chapter 5 Common Command-Line Tasks 39
Moving and Copying Files
You can move and copy les locally or remotely using the mv, cp, and scp commands.
Moving a le or folder locally
To move les or folders from one location to another on the same computer, use the
mv command. The mv command moves the le or folder from its old location and puts
it in the new location.
For example, to move a le 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 le as its moved:
mv ~/Downloads/MyFile.txt ~/Documents/Work/NewFileName.txt
For more information about the mv command, see its man page.
Copying a le or folder locally
To make a copy of a le, use the cp command.
For example, to copy a folder named “Expenses” in your Documents folder to another
volume named “Data”:
cp ~/Documents/Expenses /Volumes/Data/Expenses
You can also change the name of the folder as it’s being moved:
cp ~/Documents/Expenses /Volumes/Data/Current_Expenses
For more information about the cp command, see its man page.
Copying a le or folder remotely
To copy a le or folder to or from a remote computer, use the scp command. scp
uses the same underlying protocols as ssh. For more information about SSH, see
“Controlling Access to SSH Service” on page 22.
For example, to copy a compressed le from your home folder to the ladmin user’s
home folder on a remote server:
scp -E ~/ImportantPapers.tgz ladmin@remoteserver.com:/Users/ladmin/
Desktop/ImportantPapers.tgz
You’re prompted for the ladmin users password.
The ‘-E’ ag preserves extended attributes, resource forks, and ACL information.
For more information about the scp command, see its man page.