fbpx

Rename File In Linux – #4 Methods Guide

Rename File in Linux

Are you looking to rename a file in a Linux computer? It’s tricky, but don’t worry! Nowadays, we have lots of helpful tools to figure things out. 

While working hard on this blog post, we discovered it’s more complex than it seems! But don’t give up. We’re here to help you learn some easy ways to rename files in Linux. Keep reading to find out how!

Understanding The Linux File System 

Let’s explore the Linux File system before learning to rename files in Linux. So, be ready to jump into the world of Linux.

What is a Linux File System?

The Linux file system is like the skeleton of the computer. It helps keep everything organized by giving a place for files and folders to live. Knowing how to rename a file in Linux, and how these files and folders are arranged is essential to use Linux well.

Tree-like Structure

In Linux, the file system is like a big tree. It starts from a place called the root directory, which is like the tree’s trunk. Then, many branches called directories and subdirectories spread out from the root directory, making up the whole file system.

Hierarchical Organization

In Linux, each folder can have files and more folders inside. They’re arranged like a tree, with folders branching out. This setup helps keep everything organized and easy to handle.

Navigating the File System

Knowing how files and folders are organized in Linux lets you find stuff easily. When you use the command line, you must give the right directions to find what you need. This enables you to do things quickly and find your files easily.

File Identification

In Linux, every file has a unique address called a path. This path shows where the file is kept in the computer. A path includes all the folders the file is in and then its name. For instance, if a file named file.txt is inside a folder called documents inside another user folder, the path would be /home/user/documents/file.txt.

Method 1

Rename File in Linux Using the Command Line

Using the command line might seem scary initially, but it’s helpful and quick to rename a file in Linux. We’ll use two commands called “mv” and “rename,” which work on any type of Linux computer.

Rename Files in Linux Using the mv Command.

The mv command is like a mover for your computer files. It helps you move files and folders around in your computer’s storage. You can also use it to rename a file in Linux. So, it’s like giving a new name to your stuff! When you want to use the “mv” command, you type it like this:

mv <options> <source_file> <destination_file>

OptionsDescription
–backupSave a copy of each file you already have.
-fStop the computer from asking before replacing a file.
-iAsk before you move a file.
-uOnly move a file if the one you’re moving from is newer.
-vShow what you’re doing right now.
-nDon’t replace a file if it’s already there.
MV Commands

Rename a File in Linux Using the mv Command

If you want to change the name of one file using the mv command, just follow these steps:

mv -v <old_file_name> <new_file_name>

When you type the command, you’ll see a message below to confirm it worked. You can check what changed by using the “ls” command.

renamed ‘<old_file_name>’ -> ‘<new_file_name>’

sziMh8zB7g4F9dSbNRoeLE1or aDPxziw8LKzxKUCBShjHK8ATiI Xcw3liS8Pcc1FYtPS73 flcbGc07W mzq7cEo05IcbGbS0rGZ9X3vEM5yCvB cfLpffLCH87f SD4vzPpnDWECUVofA4rH4FVE Rename File In Linux,how to rename a file in linux,rename a file in linux,renaming the file in linux,Rename Files in Linux,rename multiple files
Rename a File in Linux Using the mv Command

In the example, we’re changing the name of a file called “mini-course-10.pdf” to “test-1.pdf” using a command called “mv.” It looks like this:

mv -v mini-course-10.pdf test-1.pdf.

Next, you can check if the file name changed by looking at what the computer shows after you use the ‘mv’ command (the one we’re talking about in the picture). You can also check by using the ‘ls’ command. When you do that, you’ll see the file with its new name in the list of files in that folder.

Tip: If you want to rename a file in Linux mv, just type in this rename command: mv old_filename new_filename

Rename Multiple Files using the mv Command.

The “mv” command helps change the names of many files in a folder at once. We’ll learn some extra tricks with it. Sometimes, the command might seem hard to get, so we’ll show you how it works with an example.

For i in *.pdf; do 

        mv -v “$i” “${i/${i:0:4}/example}”

Done

This code might seem hard at first, but it’s pretty simple. When you run it, it’ll check a list of files repeatedly. These files have names that end with “.pdf”. It will change the first four letters of each file name to “example.” It’ll keep doing this until all the files have new names.

Rename Multiple Files using the mv Command
Rename Multiple Files using the mv Command.

You can rename files in Linux in subdirectories, if you want to change the name of a file inside a folder, just tell the computer where the folder is and what you want to call the file using a command called “mv.”

Tip: If you want to change the names of many files in Linux at once, just type in this command: mv old_filename1 old_filename2 new_filename

Method 2

Rename File in Linux Using Rename Command

The “rename” command helps make renaming files easier compared to the “mv” command. It has simple rules for renaming one file or many files at once. Most computer systems already have the rename command ready to use. If it’s not there, you can add it easily with just a simple command:

Debian-based systems:

sudo apt install rename

Fedora-based systems:

sudo yum install prename

Arch-based systems:

sudo pacman -S install rename

Here’s how you can change the name of something on a computer that uses Debian:

rename <options> ‘s/<old_name>/<new_name>/’ <file_names>

When you change the name of something using the rename command, it uses a particular language called Perl behind the scenes. In Perl, there are three different ways to work with words: match, substitute, and translate. 

The rename command uses the “substitute” and “translate” ways. In the command above, the letter “s” tells the computer you want to do a substitute. If you’re using a system like RedHat or Fedora, you’ll need to type the command in this way:

rename <options> <old_name> <new_name> <file_name>

OptionsDescription
-vThis tells you what’s happening right now.
-nIt’s like a practice button to see what will happen to the files.
-fIt’s used to ensure a file gets replaced with a new one.
Rename Commands

Rename a Single File

The rename command is like the mv command when you want to change the name of just one file. To change the name of one file, use this:

rename -v ‘s/<original_name>/<new_name>/’ <file_name>

Rename a File Using Rename Commands
Rename a File Using Rename Commands

Rename Multiple Files

Here’s why using the rename command is better than the mv command when you want to rename many files. It’s easier and quicker to use. Here’s how it works:

rename <options> ‘s/<old_name>/<new_name>/’ <files_to_rename>.

We write the command almost the same as when we rename just one file. The only difference is the part where it says “<files_to_rename>.” Instead of typing the exact file name, we can use special symbols called wildcards to change many files at once, like renaming all the files that have something in common in a folder.

Rename Multiple Files Using Rename Commands
Rename Multiple Files Using Rename Commands

Rename Files Partially

Imagine if all your file names have spaces, but now you want to change them to underscores. You can do this using a command called “rename.” Here’s how:

rename -v ‘y/<original_part>/<part_to_replace>/’ <files_to_rename>

Let’s say you have something you want to change; we’ll call it the <original_part>, and you also have a pattern in mind for what you want to change it to. We’ll put that pattern inside another part called <part_to_replace>. We use “y” to show that we’re using the “translate” regular expression.

So, for example, if you want to swap spaces with underscores, you’d use this command:

rename -v ‘y/ /\_/’ <files_to_rename>.

Here, the computer thinks of the underscore as a letter, not a particular part of how commands work.

Rename Files Partially
Rename Files Partially

Change The Case of The Filenames

With the rename command; you can switch small letters to big ones and vice versa. To change small letters to big ones, just follow these steps:

rename ‘y/a-z/A-Z/’ <files_to_replace>

If you want to change big letters to small ones, just follow this pattern:

rename ‘y/A-Z/a-z/’ <files_to_replace>

Change The Case of The Filenames
Change The Case of The Filenames

Chapter 4

Renaming The File in Linux Using the GUI

The GUI method is helpful for people who fear using the command line. We use the GUI method with the Nautilus File Manager and GPrename in Ubuntu 20.04 LTS. But don’t worry; these methods will work on any computer, though we might need to change them depending on your computer type.

Rename Files Using File Manager

This is one of the simplest ways to change file names in Linux. Every type of Linux computer already has a program called a file manager, like Nautilus, Dolphin, Thunar, and others. We’ll show you how to use these programs to rename files. Just keep reading to learn how!

Rename A Single File

1. First, open the File manager you like to use. Then, find the file you want to change the name of. Click on it with the right mouse button.

2. A menu will pop up. Choose the “Rename” option from this menu. Or, you can press the F2 button on your keyboard instead of using the mouse to rename files.

Rename Option in File Manager
Rename Option in File Manager

3. You need to type a new name for the file. Then, click on “Rename” or press Enter on the keyboard. That’s all you have to do!

New File Name
New File Name

Rename Multiple Files Using File Manager

  1. Hold the Shift key and click on all the files you want to rename.
  2. After selecting them, right-click on any of the chosen files.
  3. A menu will pop up. Choose the “Rename” option.
  4. Or, just press the F2 button on your keyboard to rename the files.
Renaming Multiple Files Using File Manager
Renaming Multiple Files Using File Manager
  1. When you click on this, a new window will appear to rename stuff, as shown here. You’ll see two choices for renaming files. Let’s learn how to use each one step by step.

If you want to rename files in Linux in bulk at once, just type in this command: mv old_filename1 old_filename2 new_filename

Rename File in Linux Using a Template

  1. You’ll find a box with words already called [Original file name] when you pick this choice. Type in a name that you want to use for all the files.
Original File Names Box
Original File Names Box
  1. So, we call all our files “test_.” Then, click the “Add” button next to that name and pick the automatic numbering option. This helps each file have its memorable name.
Unique Identifiers
Unique Identifiers
  1. Next, decide how to name your files. You can choose if you want them to go in order from smallest to biggest, most significant to smallest, or something else.
Ordering Option
Ordering Option
  1. Check the changes at the bottom. Then, click “Rename” at the top right.
Changes Preview
Changes Preview

Find and Replace Text

Here’s a simple way to change a name in a file if it’s already a name many people use. Follow these steps:

  1. Type the old name in the box that says “Existing Text.” You’ll see it highlighted below.
  2. In the box that says “Replace With,” type the new name you want to use instead.
  3. Check if everything looks right below, then click “Rename” at the top to make it official.
Find and Replace Text
Find and Replace Text

Method 3

Rename File in Linux Using GPRename

GPRename is a simple tool for changing many file names simultaneously on a Linux computer. It has different choices to help you when you’re changing names. This tool is suitable for people who struggle to change many file names simultaneously as their usual file program. But you have to install it yourself with these commands:

Debian-based systems:

sudo apt update && sudo apt install gprename

Fedora-bassed systems: 

sudo dnf install gprename

Arch-based systems:

sudo pacman -S gprename

Rename A Single File with GPRename

  1. First, find and click on GPRename in the Applications menu or type “gprename” in the particular place called the Linux Terminal.
  2. Next, look at the tree on the left side of the screen. This helps you move around to find the folder where your file is. Then, click on the file you want to give a new name on the right side of the screen.
Rename File in Linux Using GPRename
Rename File in Linux Using GPRename
  1. Look down at the bottom part of the screen. There, you’ll see some choices of what you can do. Say you want to change a word in a file name to a different word. Click on the tab that says “Replace/Remove.” Then, type the word you want to change in the box labeled “Replace” and the new word in the box labeled “With.”
  2. Click the ” Preview ” button on the right side to check out the changes. If everything looks good, click on the button below that says “Rename.” That’s it! You’re all set.
Rename File in Linux Using GPRename
Rename File in Linux Using GPRename

Rename Multiple Files with GPRename

  1. Look at the list on the left to find the folder you want. Click on it. Then, pick the files you want to rename. At the bottom, choose what you want to do next.
Choose Multiple Files To Rename
Choose Multiple Files To Rename
  1. To check the changes, tap the preview button on the right side. Then, hit the “Rename” button below it.
Preview Changes
Preview Changes

Method 4

Rename File in Linux With Hosting Account

In this part, we will take a quick look at how to change file names in Linux using the CPanel Method.

Rename Files in Linux With Cpanel

If you put a file on your Linux Hosting account, you can give it a new name.

  1. Go to the page for your stuff.
  2. Under the part called Web Hosting, find the Linux Hosting you want to use, then click on Manage next to it.
Rename File in Linux With Cpanel
Rename File in Linux With Cpanel
  1. Go to the top left corner of your account Dashboard and click on “File Manager.”
Rename File in Linux With Cpanel
Rename File in Linux With Cpanel
  1. Go to the cPanel File Manager. Find the file you want to change. Click on it, then choose Rename. Type in the new name for the file and hit Enter/Return.

Conclusion

When you’re just starting, knowing how to handle files in Linux is reasonable. Renaming the file in Linux is a task you’ll do a lot. In this guide, we’ll teach you four ways to rename files: two using commands you type and two using buttons and menus.

Most people will use the file manager to rename files. But some folks like to use special commands called “mv” and “rename” in the Terminal. These commands are handy for renaming files quickly. You can also get a unique control panel tool to help you manage files with buttons and menus.

Leave a Reply