![]() Both the directories are named in lower case. Suppose I have two directories, ‘ game‘ and ‘ work‘. Rename Multiple Directories at Once Using rename Command ![]() We will rename the directory named dir2 as ssh.ĭIR1 dir2 dir3 dir4 dir5 pc snap :~# rename 's/dir2/ssh/' dir2ĭrwxr-xr-x 2 root root 4096 Sep 9 15:15 DIR1ĭrwxr-xr-x 2 root root 4096 Sep 9 15:15 dir3ĭrwxr-xr-x 2 root root 4096 Sep 9 15:15 dir4ĭrwxr-xr-x 2 root root 4096 Sep 9 15:15 dir5ĭrwxr-xr-x 3 root root 4096 Sep 9 14:59 snapĭrwxr-xr-x 2 root root 4096 Sep 9 15:15 sshįrom the above output we can see that directory named ‘ dir2‘ is renamed as ‘ ssh‘ using the rename command. We will try renaming a single directory first using rename command. Install rename on Fedora, CentOS, and RedHat distributions: sudo dnf install prenameĪfter installing rename on your Linux computer, use the code below rename a single directory. Install rename on Ubuntu and Debian distributions: sudo apt-get install rename The only difference will be with the commands to install the rename utility. But their functioning will be the same in all the environments. rename is available in two different versions. You will have to install it separately first. Rename doesn’t come built-in with the Linux distribution. To overcome these shortcomings we can use the rename command to rename multiple files at once. Using rename Command To Rename DirectoriesĪs already mentioned above, mv is a very basic command and also has some ambiguous behaviour. ![]() To avoid such ambiguity we can use the rename command. This is the lacunae in using the mv command if there exists more than one directories with the same name. Here directory qps already existed but even then the overwriting prompt was not shown by the terminal.Īlso, you can see that the directory named ‘ dmta‘ has been deleted. ![]() Here I tried to rename directory ‘ dmta‘ as ‘ qps‘. If you try to rename a directory to a name already used by another directory in the desired location, the directory with the old name will be deleted and over-written with the new one.Įxample: :~/workspace$ ls -lĭrwxr-xr-x 2 root root 4096 Sep 9 16:19 dmtaĭrwxr-xr-x 2 root root 4096 Sep 9 16:20 pcĭrwxr-xr-x 2 root root 4096 Sep 9 15:19 pmcdĭrwxr-xr-x 2 root root 4096 Sep 9 16:19 robotįrom the above list, let’s work with the directories dmta, pc and qps.Įxample Output: :~/workspace$ mv dmta qps Then, check the list of directories again using the ls command to verify the new name of the directory. Now, we will rename the folder named daa to robot using the mv command. Syntax: mv įirst, check the directories present in the current working directory using the ls command. Use the following syntax to rename a directory using mv. But it’s also widely used as a way to rename a files and directories as well. mv is basically used to move the files from one location to the another. The mv command is one of the basic commands provided by Linux and all other Unix-like systems. Using mv Command To Rename a Directory in Linux We will be discussing two Linux commands to rename the directories in Linux. Fortunately, Linux has an effortless way of renaming files and directories directly from the terminal. Renaming the files and directories is a frequent task that a user has to carry out. A basic guide to rename a single or multiple directories in Linux using only command line utilities
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |