
Manage files in Terminal on Mac
In Terminal, you can move and copy files locally or remotely using the mv, cp, and scp command-line tools.
Tip: It’s easier to move and copy files using the Finder. See Organize files in folders.
Move a file or folder locally
Go to the Terminal app
on your Mac.Use the
mvcommand to move files or folders from one location to another on the same computer. Themvcommand 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.txtYou can also change the name of the file as it’s moved:
% mv ~/Downloads/MyFile.txt ~/Documents/Work/NewFileName.txt
See the mv command man page.
Copy a file or folder locally
Go to the Terminal app
on your Mac.Use the
cpcommand to make a copy of a file.For example, to copy a folder named Expenses in your Documents folder to another volume named Data:
% cp -R ~/Documents/Expenses /Volumes/Data/ExpensesThe
-Rflag causescpto copy the folder and its contents. Note that the folder name does not end with a slash, which would change howcpcopies the folder.
See the cp command man page.
Copy a file or folder remotely
Go to the Terminal app
on your Mac.Use the
scpcommand to copy a file or folder to or from a remote computer.scpuses 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.tgzYou’re prompted for the user’s password.
The
-Eflag preserves extended attributes, resource forks, and ACL information.The
-rflag, which isn’t used in this example, causesscpto copy a folder and its contents.
See the scp command man page.