Skip to content

spo file rename

Renames a file

Usage

m365 spo file rename [options]

Options

-u, --webUrl <webUrl>
The URL of the site where the file is located
-s, --sourceUrl <sourceUrl>
Site-relative URL of the file to rename
-t, --targetFileName <targetFileName>
New file name of the file
--force
If a file already exists with target file name, it will be moved to the recycle bin. If omitted, the rename operation will be canceled if a file already exists with the specified file name
-h, --help
output usage information
--query [query]
JMESPath query string. See http://jmespath.org/ for more information and examples
-o, --output [output]
Output type. json,text,csv. Default json
--verbose
Runs command with verbose logging
--debug
Runs command with debug logging

Remarks

If you try to rename a file without the --force flag and a file with this name already exists, the operation will be cancelled.

Examples

Renames a file with server-relative URL /Shared Documents/Test1.docx located in site https://contoso.sharepoint.com/sites/project-x to Test2.docx

m365 spo file rename --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl '/Shared Documents/Test1.docx' --targetFileName 'Test2.docx'

Renames a file with server-relative URL /Shared Documents/Test1.docx located in site https://contoso.sharepoint.com/sites/project-x to Test2.docx. If the file with the target file name already exists, this file will be moved to the recycle bin

m365 spo file rename --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl '/Shared Documents/Test1.docx' --targetFileName 'Test2.docx' --force