- Rename folder on Linux
- Rename folder on Linux
- Move directory in Linux
- Rename folder in Linux using the command “mv” and “find”
- How to rename Many Folders
- Rename command for Linux
- Renaming multiple directories with rename
- Selecting folders to be renamed
- How to Rename Multiple Files In Linux
- mmv Linux Command
- Reame file append date on Linux
- Conclusion
- Rename Folder in Linux
- Renaming directories using mv command
- Renaming directories using find command
- Renaming directories using the rename command
- Syntax:
- Renaming directories using the Bash script
- Getting Help
- Feedback
- Help Others, Please Share
- Learn Latest Tutorials
- Preparation
- Trending Technologies
- B.Tech / MCA
- Javatpoint Services
- Training For College Campus
Rename folder on Linux
Rename folder on Linux, it’s an easy process, and there is more than one command for this goal. We will discuss this article. Also, rename folder in Linux follows the same process for any file.
So, we will learn how to use the command ‘mv‘ (short of move) to rename or move a folder. In addition, we will go through the command ‘rename’ that also we can rename folder in Linux.
Also, It is vital to conserve the file system structured to facilitate access to the data.
Rename folder on Linux
First, let’s see how we can make it using the mv command and how it works.
The syntax of the mv command for moving folders is as bellow:
mv [OPTIONS] source destination
For example, to rename the directory bitslovers as bitslovers-temp can run:
When renaming folders, you must define precisely two parameters to the mv command. The first parameter is the target folder name that you want to rename, and the second one is the new name.
Move directory in Linux
It is noteworthy that if the bitslovers-temp already exists, the bitslovers folder is moved to the bitslovers-temp directory.
Rename folder in Linux using the command “mv” and “find”
In some scenarios, you may not know right where your folders are placed on your system.
Fortunately for you, a command supports you finding and discovering folders on a Linux system, the find command.
So, to find and rename folders on Linux, use the “find” command with the “type” option to scan for folders. You can then transfer your folders by performing the “mv” command with the “-execdir” option.
Let’s see how easy to find and rename folders:
In addition, let’s assume that you need to rename folder starting with “backup” on your filesystem to “old-backup.”
The first section of the command will find where your folder is placed.
As a result, you know where your folder is. You can rename it by utilizing the “execdir” option with the “mv” command.
How to rename Many Folders
Renaming a single folder is an uncomplicated task, but renaming multiple folders at once can be a difficulty, particularly for new Linux users.
Also, renaming multiple folders at once is unusually wanted.
To rename multiple folders on Linux, generate a new script file and use the “mv” command in a “for” loop to repeat over folders.
bash find and rename folders:
Let’s explain the script steps:
- The first line generates a loop and iterates over a list of all files.
- The second line from our script analyses if the file is a folder.
- The third line adds the current date to a specific folder.
Rename command for Linux
Renaming multiple directories with rename
First, let’s install the rename package:
How to install rename package on Ubuntu or equivalent:
Instead of utilizing the “mv” command, you can adopt a dedicated built-in command. But, this command may not be immediately available on your Linux version.
The rename command is applied to rename many files and folders in Linux. This command is more unconventional than mv as it requires a fundamental knowledge of regular expressions.
To rename a folder in Linux, use “rename” with how you need the files to be renamed and the target folder.
For example, let’s suppose that you need to rename all your folders that start with “photos-BACKUP” to “photo-backup.” In other words, replacing the uppercase to lowercase.
Selecting folders to be renamed
For example, you may want to rename only a few folders using the rename command.
So, you basically have two choices :
- Employ wildcards to filter folders to be renamed.
First, if you need to rename folders ending with a given characters sequence, you would reach that by using the following command.
The syntax above by the rename command is identical to the sed command.
So, you can use input redirection to filter folders to be renamed.
When applying one of those two options, your folders will be renamed to have a “_backup” in the end.
How to Rename Multiple Files In Linux
There are many commands and utilities to a rename bunch of files. However, let’s focus on the most used command for that proposal. And also how to rename files with regex.
mmv Linux Command
The mmv command is applied to copy folders, move, add and rename files in bulk using conventional wildcards in Linux/Unix-like operating systems. To install it on Ubuntu, Mint, Debian, you can run the command below:
For example, you have the following files in your current directory.
And you need to rename all files that start with the word “year” to “2021”.
I have sure that you don’t want to do it manually because we have 100 pictures in that folder. With the mmv command, it’s easy and straightforward.
Reame file append date on Linux
To rename all files starting with the word “year” to “2021”, just run:
To verify if the files have been renamed or not.
Clarification
Let’s go deep, what this command did —the first argument (picture-year\*) is the pattern that we are looking for.
The second parameter is an argument that we would like to replace ( picture-2021\#1 ).
So, mmv will scan for any filenames starting with the word ‘picture-year’ and rename the matched files according to the second argument we are trying to replace. Also, the wildcards, such as ‘*,’ ‘?’ and ‘[]’, were used to meet one or more random characters. Please be careful that you must escape the wildcard characters; oppositely, they will be extended by the shell, and mmv won’t recognize them.
Regarding the ‘#1′ in the is a wildcard index. It meets the first wildcard located in the first argument pattern. For example, if we have ‘#2′, that would match with the second wildcard and so on. In other words, if we have only one wildcard (*), because of that, we use #1.
Furthermore, the hash sign should be escaped too.
Another example, it’s possible to rename all files with a specific extension to another extension. Like, to rename all .data files to .json file format in the current directory, simply run:
Let’s see a second example. Let us assume you have the following files.
And you need to replace the first appearance of new with old in every file in the current folder. To accomplish that, it’s super easy:
Conclusion
So, you learned several ways of renaming folders on Linux, the common with “mv” command. All new users that are starting on Linux should know at least the mv command.
Also, like many commands on Linux, we can combine multiples commands to achieve a single goal. To rename the folder, it’s possible to use the “mv” with “find” to give us more versatility and power.
Rename Folder in Linux
In Linux, the renaming process of a folder or directory is not done with a traditional rename command; instead it is done through the ‘mv’ command. The ‘mv’ command is a multi-purpose command. It is not just limited to move files and directories, but it can also be used for renaming the files and directories.
It is important to keep the file system structured to ease access to the data. Sometimes, we create some temp files, and later we need to rename them. In such cases, it is a handy tool.
However, the directories can be renamed using various commands and utilities such as mv command, find command, rename command, using Bash, and more.
Let’s have a look at the following techniques of renaming directories:
Renaming directories using mv command
Basically, the mv command is used to move files, but we can also rename the folders and directories by it. We can simply rename the folders by executing the mv command, followed by the old folder name and new folder name, respectively.
For example, to rename a folder named as ‘Old_folder’ to ‘New_folder,’ execute the command as follows:
The above command will rename the folder.
Execute the ls command to list all the available files and folders in your current working directory:
Consider the below output:
Renaming directories using find command
In some cases, we don’t know exactly where the required directories are located. The find command assists us in finding and locating the directories in the Linux system.
To find the directories use the find command with the ‘type’ option to look for directories from the file system. We can rename them by executing the mv command with the ‘-execdir’ option.
For example, to rename the ‘New_folder’ directory, execute the below command to find it:
The above command will locate the directory from the file system. If you don’t remember the exact directory name, you can type the matching directory name. Consider the below output:
Now, to rename the directory, execute the mv command with ‘-execdir’ option as follows:
The above command will rename the directory as ‘Directory’. We can list the files and directories using ls command as follows:
Consider the below output:
Renaming directories using the rename command
The rename command is a built-in utility to rename the files and directories for the most Linux distribution. However, it may not be directly available for all the Linux distribution.
Instead of the mv command, we can rename files using the rename command. It allows us to rename multiple files and directories. We can rename multiple directories together, such as rename all the text directories into any other format, rename all the directories which are in lowercase to uppercase, and more.
Syntax:
In order to use the rename, we must have it on our machine. If it is not installed, it will display the output as follows:
To install the rename, execute the command as follows:
It will start a daemon process and install the rename configurations on our machine. Consider the below output:
The rename configurations are successfully installed on our machine. Now we will use the rename command. Consider the following examples:
Example1: If we want to rename our directories written in uppercase to lowercase. To display the directories, execute the ls command as follows:
the above command will display all the directories from the current working directory. Consider the below output:
Now, perform the rename operation, execute the below command:
The above command will rename all the directories from uppercase to lowercase.
To verify the operation, list all the directories by executing ls command:
Consider the below output:
As from the above output, all directories are renamed as in lowercase.
Example2: Rename all text files into pdf files.
We can rename all ‘.txt’ extension file as ‘.pdf’ extension. We have the following text files in our current working directory:
To rename all text files as pdf files, execute the command as follows:
The above command will rename all the text files into pdf files. Consider the below output:
Renaming directories using the Bash script
we can rename files and directories using the Bash scripting language. In order to rename multiple directories by using a Bash script, create a new script, and use an ‘mv’ command with for loop. let’s understand the following example:
First, create some text files which can be renamed later. To create 10 files at once, execute the below script:
The above script will create 10 text files. Consider the below commands:
To verify whether the files are created or not, execute the below script:
The above script will display all the created files. Consider the below output:
Now create a variable ‘newfile,’ execute the below script:
The above script will create a variable ‘newfile’ and replace all the ‘.txt’ extension with ‘.zip’ extension. The echo command will display the variable values. Consider the below output:
Now, we can rename all the files using the mv command. To rename files with mv command using a bash script, execute the below script:
Consider the below script:
The above script will convert all the text files into zip files. To list the files, execute the ls command as follows:
The above command will list the files with time and other specified options. Consider the below command:
Getting Help
If you stuck during the use of the rename command, you could get help from the command line by executing the below command:
The above command will display all the available options that can be used with the rename command. Consider the below output:
As from the above output, we can see that the options are displayed with their usage.
Also, we can read the manual by executing the below command:
The above command will display the manual on your terminal. Consider the below output:
Scroll the above manual to read more. To exit from the terminal window, press the ‘q’ key.
Feedback
Help Others, Please Share
Learn Latest Tutorials
Python Design Patterns
Preparation
Trending Technologies
B.Tech / MCA
Javatpoint Services
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
- Website Designing
- Website Development
- Java Development
- PHP Development
- WordPress
- Graphic Designing
- Logo
- Digital Marketing
- On Page and Off Page SEO
- PPC
- Content Development
- Corporate Training
- Classroom and Online Training
- Data Entry
Training For College Campus
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week