

In order to achieve that, you essentially have two options : In some cases, you may want to rename only a few directories using the rename command. In order to rename those directories, you would run the following command $ rename 'y/A-Z/a-z/' *ĭrwxrwxr-x 2 user user 4096 Dec 21 02:26 a_tempĭrwxrwxr-x 2 user user 4096 Dec 21 02:26 b_temp Filtering directories to be renamed


$ rename Īs an example, let’s say that you want to rename all your directories written in uppercases to directories names in lowercase letters. In order to rename directories on Linux, use “rename” with how you want the files to be renamed as well as the target directory. Instead of using the “mv” command, you can use a dedicated built-in command, however this command may not be directly available on your distribution. $ lsĬongratulations, you just renamed directories using a Bash script on Linux.
Linux rename user free#
Feel free to customize this line in order to rename the directories however you want them to be renamed. Then, if the directory exists, it is renamed to have a “_temp” extension at the end. We are testing if the entry is a directory and if the directory exists using the “-d” option. In this script, we are listing all the files and directories that are located in the current working folder (where the script is located). Save this script as “change_name” and add it to your PATH environment variable if you want to use it on your entire system. depth -type d -name -execdir mv _temp" || echo 'Could not rename '"$directory"'' You can then remove your directories by executing the “mv” command with the “-execdir” option. In order to find and rename directories on Linux, use the “find” command with the “type” option in order to look for directories. Luckily for you, there is a command that helps you find and locate directories on a Linux system : the find command. In some cases, you may not know directly where your directories are located on your system. $ ls -l /home/userĭrwxr-r-x 2 user user 4096 Nov 9 16:41 Desktop/ĭrwxr-xr-x 2 user user 4096 Nov 9 16:41 Documents/ĭrwxr-xr-x 2 user user 4096 Nov 9 16:41 Downloads/ĭrwxr-xr-x 2 user user 4096 Nov 9 16:41 Music/ĭrwxrwxr-x 2 user user 4096 Dec 20 10:53 directory/Īwesome, you just renamed a directory on Linux. Now if you take a look at all the directories stored in your home directory, you will see a new entry for your “directory” folder. Note : using the mv command will not delete the content stored inside your directories, you won’t lose any files by renaming your directories on Linux. $ mv /home/user/temp /home/user/directory To rename this directory, you would use the “ mv” command and specify the two directory names. $ mv įor example, let’s say that you want to rename a specific directory on your filesystem named “temp” (located in your home directory) to “directory” (also in your home directory) To rename a directory on Linux, use the “mv” command and specify the directory to be renamed as well as the destination for your directory.
