In this tutorial, we explain how to rename a directory in Linux, using the “mv” and “rename” commands.
Renaming directories is not very different from renaming files. Because after all, this is Linux, where everything is a file. Even the directories. So, most of what we discussed with renaming files works here too.
Renaming directories with mv
mv RenameDir/ renameDir
There it is. Just mv it, like the song. Only special concerns, if you have anything directed to the directory. Make sure to search your files for any mention of the name.
This way you can find any reference to the old directory name. Go ahead and search and replace to change it to match.
Rename multiple directories with rename
Same as with files, use rename.
NAME rename - rename files SYNOPSIS rename [options] expression replacement file...
If you want to learn more about the process, look to the renaming files article, where I go into more detail.
rename foo foo0 foo*
And that’s it, add a 0 to a directory name. Add anything, or rename anything.
Conclusion
Renaming directories is a simple task. It’s very similar to renaming files. The only caveat, it’s important to remember that your scripts are not targeting that directory.