import Global from '/docs/cmd/_global.mdx';
Copies a file to another location using the Microsoft Graph
m365 file copy [options]
`-u, --webUrl <webUrl>`
: The URL of the site where the file is located.
`-s, --sourceUrl <sourceUrl>`
: Server-relative or absolute URL of the file.
`-t, --targetUrl <targetUrl>`
: Server-relative or absolute URL of the location.
`--newName [newName]`
: New name of the destination file.
`--nameConflictBehavior [nameConflictBehavior]`
: Behavior when a document with the same name is already present at the destination. Possible values: `fail`, `replace`, `rename`. Default is `fail`.
Copy a file by server-relative URL to a document library in another site collection with server relative URL
m365 file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceUrl "/sites/project/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents"
Copy a file by absolute URL to a document library in another site collection with absolute URL
m365 file copy --webUrl https://contoso.sharepoint.com --sourceUrl "https://contoso.sharepoint.com/Shared Documents/Document.pdf" --targetUrl "https://contoso.sharepoint.com/sites/IT/Shared Documents"
Copy a file to a document library in another site collection and rename the file
m365 file copy --webUrl https://contoso.sharepoint.com --sourceUrl "/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents" --newName "newName"
Copy a file to a document library in another site collection and rename the file if a file with the same name already exists.
m365 file copy --webUrl https://contoso.sharepoint.com --sourceUrl "/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents" --nameConflictBehavior rename
Copy a file to Onedrive for business
m365 file copy --webUrl https://contoso.sharepoint.com --sourceUrl "/Shared Documents/Document.pdf" --targetUrl "https://contoso-my.sharepoint.com/personal/john_contoso_onmicrosoft_com/documents"
The command won't return a response on success.