9/8/2023 0 Comments Linux mass renameTo do so: $ prename -v 'y/a-z/A-Z/' *dir*Īs you can see, all the directories were renamed to use uppercase characters. Another example would be if we wanted to rename all the directory names to be uppercase rather than lower. This will replace all the directory names that have ‘directory’ in their name, with ‘dir’. With prename we can use syntax such as the following: $ prename -v 's/directory/dir/' * Very similar to rename, it offers a different way to write the expression used to rename the specified directories, which is based on sed. Prename is available on Fedora and Redhat-derived distributions. Using prename on Fedora and RedHat to rename a Linux directory We could use the rename command as follows (including the -v switch to get a verbose output): $ rename -v dir directory dir?Īll the directories have been renamed successfully. What if we wanted to rename these directories to be directory1, directory2 and director圓. 2 centos centos 19 Dec 11 16:14 dir2ĭrwxrwxr-x. 2 centos centos 6 Dec 11 17:02 dir1ĭrwxrwxr-x. For example, say we have a bunch of directories all starting with dir: $ llĭrwxrwxr-x. Ok, so how does it work? Rename works by having you specify an expression, to tell it how to rename the directories, and the target(s). On Ubuntu and Debian-derived distributions you can install rename like this: $ sudo apt-get install renameĪnd on Fedora and RedHat-derived distributions you can install it with this: $ sudo dnf install prename If not you should be able to easily install it. Most Linux distributions will also have the rename command available. However, mv isn’t the only way to do it, and whilst mv works well for renaming single directories, it doesn’t have any inbuilt capability for renaming multiple directories (though there are ways to have mv do this, more on that later). That’s how straight forward it is to rename Linux directories using the mv command. You can confirm the that renaming the directory has worked as expected by listing the contents of the parent directory, which in this example is my home folder: $ ls -lah /home/centos/Īs you can see in the image above, I now have a directory called dir2. The mv command simply changes the directory name, it doesn’t affect any of the files contained within. If the directory contains any files, they will be left unchanged. Nice and easy! So as a practical example, if I had a directory in my home folder called dir1 and I wanted to rename the directory to dir2 I could use the mv command like this: $ mv /home/centos/dir1 /home/centos/dir2 The syntax to use mv to rename a directory on Linux is as follows: $ mv sourcedir targetdir And, we can use it to ‘move’ a directory to a new name. It supports moving single files, multiple files and whole directories. The mv command is a command line utility that moves files or directories from one place to another. The command most often used to rename directories in Linux is the mv command, so that is where we will start! Rename Directories on Linux I’ll be using my CentOS system for the examples in this article, but it will be much the same for other distributions. We will start by giving some simple examples of how to do so using the command line tools commonly available on Linux distributions, then move onto some more advanced examples. This article aims to help you out if you need to rename a directory on Linux, or multiple directories at the same time. If you are from a Windows background, you may not yet be familiar with the ways and commands to rename directories on Linux. File-system management is an important skill to have if you are working with Linux systems often.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |