In this article, we will show you how some quick steps in order to rename folder in CMD or Command-Line in both operating systems such as Windows and Linux. Geeks and experts love the Command-Line because of the advanced commands it can run. Fortunately, Command-Line is not built only on advanced commands, but also on simple ones, designed to perform basic operations. Just in case if you want to rename the file using Command Line (CMD) & PowerShell check our previous article – “ Batch script rename file using Command Line (CMD) & PowerShell – Windows 10 “
What you need to know before starting rename folder
- You must have written or modified permissions to a file, folder, or directory to rename it. In some cases, you may need administrator privileges in the operating system to rename.
- Whenever dealing with a file or directory with space, it must be surrounded by quotes. Otherwise, you’ll get the “The syntax of the command is incorrect.” error.
- With ren command, you can’t move the files to another drive or directory. This command just renames the existing file/folder and does not create a new file. That is why it does not accept the full path for the target file name. If you try to do that you will get the error – “The syntax of the command is incorrect.”
Windows CMD Rename Folder
To rename files and folders, you need to use the REN (Rename) command. Because you cannot have a file and directory of the same name, you won’t need to worry about mistakenly renaming a file instead of a directory. The only exception is if you’re using wild characters. To rename a folder in the command line, type the following command:
ren Folder NewFolderName.
Note: We can also use ren (the short form of rename) for rename operations. Both Ren and Rename refer to the same command.
For example, if we wanted to rename the HelloWorld folder to HelloWorld_2021, we should run “ren HelloWorld HelloWorld_2021” and press Enter.
Step 1: Change the location in order to select the folder you want to rename by typing the following command:
cd D: D:
Step 2: Rename folder in CMD using ren command:
ren HelloWorld HelloWorld_2021
Linux Rename Folder Command
You need to use the mv command to rename and move files and directories/folders. Everything is a file under Linux or Unix-like operating system including folders.
The procedure to rename a folder or directory on Linux:
- Open the Terminal application.
- The pwd commandshows current working directory:
mv command syntax form is as follows:
mv old-name new-name mv [options] old-name new-name mv [options] source target
- To rename a directory called HelloWorld to Hello in the current directory:
pwd ls -l mv HelloWorld Hello
- Verify it with the ls command:
If the Hello folder is located in the same directory as the pics folder, then the HelloWorld folder can only be renamed. Hence always use pwd command and ls command to find out your current working directory.