Knowledgebase
How to rename files and folders via SSH
To rename files and directories on your hosting account through SSH you can use the mv command. The same command is also used to move files and folders, but in this article will concentrate on the rename function. To rename a file that's in the current working directory use the command followed by the file that you want to rename and then the new name for the file (separate the two names with a space and include the file extension). For example:
mv example.txt example2.txt
will rename the file example.txt that's in the current working directory into example2.txt. If a file with the destination name (example2.txt in our case) already exists, it will be replaced by the new file with the same name. As usual, if the file that you want to rename has spaces in its name, or you want the new name to have spaces in the name, put quotation marks around the name (e.g. mv "example file.txt" "example file2.txt"). If you want to rename a file that's not in the current working directory and you don't want to change the directory, you can use the full path to the file. For example:
mv /home/username/public_html/example.txt /home/username/public_html/example2.txt
will rename the file example.txt that's in the public_html folder into example2.txt.
Exactly the same rules apply when renaming a directory. For example:
mv folder folder2
will rename a directory called folder that's in the current working directory into folder2.
For information on how to use the mv command to move files and folders check out the article on moving files and folders via SSH.