Batch Convert Multiple Files to Lowercase in Linux

Converting multiple files to lowercase can be a tedious task, especially when dealing with large numbers of files. In this post, we’ll show you how to use the for loop and tr command in Bash to achieve this efficiently.

Introduction

If you’re working with text files or need to standardize file names across your system, converting multiple files to lowercase can be a time-consuming task. However, Linux provides an easy way to accomplish this using a simple script.

Step 1: Open the Terminal

To start, open a terminal window on your Linux system.

<--- line with title and tags --->

Step 2: Navigate to the Directory Containing the Files

Next, navigate to the directory that contains the files you want to convert. You can do this using the cd command.

cd /path/to/directory

Replace /path/to/directory with the actual path to the directory containing your files.

Step 3: Run the Batch Conversion Script

Now, run the following script to convert all files in the current directory to lowercase:

for i in *; do mv "$i" "`echo "$i" | tr [A-Z] [a-z]`"; done

Explanation of the Script:

  • for i in *;: This loop iterates over all files and directories in the current directory.
  • do mv "$i" "echo “$i” | tr [A-Z] [a-z];: For each file, this line moves it to a new location with its name converted to lowercase using the tr command.

Final Note

After running the script, all files in the directory will have their names converted to lowercase. This can save you time and effort when working with text files or standardizing file names across your system.