Wednesday, February 8, 2023
  • Events
  • Interviews
  • Jobs
  • Opinion
  • Whitepapers
  • Glossary
  • Community Forum
  • Web Hosting Directory
  • Login
  • Register
Cloud7 News
  • Cloud Computing
  • Web Hosting
  • Data Center
  • Linux
  • Cybersecurity
  • More
    • Network/Internet
    • Windows
    • Software
    • Hardware
    • Blockchain
    • Policy/Legislation
    • How-Tos
    • Troubleshooting
No Result
View All Result
Cloud7 News
  • Cloud Computing
  • Web Hosting
  • Data Center
  • Linux
  • Cybersecurity
  • More
    • Network/Internet
    • Windows
    • Software
    • Hardware
    • Blockchain
    • Policy/Legislation
    • How-Tos
    • Troubleshooting
No Result
View All Result
Cloud7 News
No Result
View All Result

Home > How-Tos > How to rename a file in Linux

How to rename a file in Linux

Linux provides various ways to do basic tasks such as renaming a file. You can rename files using a GUI file manager or via the command-line terminal.


Ugur Kubilay Cam Ugur Kubilay Cam
September 4, 2021
3 min read
How to Rename a File in Linux

There are two approaches when you rename files in Linux: via the command-line interface or the command-line. The command line is also known as the terminal. Terminal is an essential tool for administrating Linux servers, which provides Linux users with some of the best productivity tools with full power.

Table of Contents

  • Rename a file in Linux terminal using “mv” command
  • Renaming multiple files
    • Rename multiple files using the “rename” tool
      • Basic usage
      • lowercase to UPPERCASE
      • Verbose mode
    • Rename multiple files using the for loop
  • Rename a file using right-click
  • Rename a file by pressing F2 key

Rename a file in Linux terminal using “mv” command

To rename a file in the Linux terminal, enter the following command at the command line.

[email protected]:~$ mv oldFileName.php newFileName.php

You can change the name of the file located in a different folder in the current folder.

[email protected]:~$ mv /path/to/file/oldFileName.php /path/to/file/newFileName.php

Note: Actually the mv command is used to move a file.


Renaming multiple files

You can use the rename tool and the for loop to rename multiple files on Linux terminal.

Rename multiple files using the “rename” tool

First, we need to install the rename tool. Most Linux distributions do not come with a rename tool. Run the following command in the terminal to install the tool:

Install rename on Ubuntu / Debian

[email protected]:~$ sudo apt install rename

Install rename on CentOS / Fedora / AlmaLinux / Rocky Linux

[email protected]:~$ sudo yum install prename

Install rename on Arch Linux

[email protected]:~$ yay perl-rename ## or yaourt -S perl-rename

Basic usage

If you want to rename txt files to HTML, you can use the command below.

[email protected]:~$ rename 's/\.html$/\.php/' *.html

lowercase to UPPERCASE

You can use the following command to convert lowercase filenames to uppercase.

[email protected]:~$ rename 'y/A-Z/a-z/' *.jpeg

Verbose mode

You can use the -n parameter to output the command you used in verbose.

[email protected]:~$ rename -n 's/\.html$/\.php/' *.html

index.php renamed as index.html
services.php renamed as services.html
about.php renamed as about.html

Rename multiple files using the for loop

For example, we want to add dates to pdf file names.

[email protected]:~$ ls
file1.pdf
file2.pdf
...
file3.pdf

The bash script below will add the date to all pdf files in the current folder.

for i in $(ls *.pdf); do
mv $i $(basename $i .pdf)_$(date +%Y%m%d).pdf 
done

After running the code, we see that the filenames have changed.

[email protected]:~$ ls
file1_20210210.pdf
file2_20210210.pdf
...
file3_20210210.pdf

Note: If you need help renaming multiple files, you can post a comment on this page.


Rename a file using right-click

If you have the GUI, right-click the file you want to rename and click “Rename”.

Rename a file usging right click in Linux


Rename a file by pressing F2 key

If you have the GUI, click once on the file you want to rename and press F2.

Rename a file by pressing F2 key in Linux

 

Ugur Kubilay Cam

Ugur Kubilay Cam

Ugur Kubilay Cam is the content marketing specialist of Cloud7 News. In addition to being an SEO expert, Ugur Kubilay is a Python developer and cybersecurity researcher. Ugur has a Bachelor's degree and a master's degree in Data Analysis. With more than 15 years of experience, Ugur Kubilay Cam is an active Linux user and administrator.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I agree to the Terms & Conditions and Privacy Policy.

Next Post
Datadog launches cloud security platform

Datadog to present at upcoming investor conferences

Related News

Red Hat brings new security capabilities to Red Hat OpenShift

Red Hat brings new security capabilities to Red Hat OpenShift

February 7, 2023 8:55 pm
First look at Gnoppix Linux 23.2

Gnoppix Linux 23.2 is ready to download

February 6, 2023 9:30 pm
Red Hat Enterprise Linux is joining the Oracle Cloud Infrastructure

Red Hat Enterprise Linux now runs the Oracle Cloud Infrastructure

February 6, 2023 7:00 pm
Best Ubuntu alternatives for desktop of 2023

Best Ubuntu alternatives for desktop of 2023

February 4, 2023 12:20 pm
Get free daily newsletters from Cloud7 News Get the Cloud7 Newsletter
Select list(s):

Check your inbox or spam folder to confirm your subscription.

By subscribing, you agree to our
Copyright Policy and Privacy Policy

Get the free newsletter

Subscribe to receive the latest IT business updates straight to your inbox.

Select list(s):

Check your inbox or spam folder to confirm your subscription.

Editor's Choice

What’s new in Linux kernel 6.2 rc6?

10 Best Web Hosting Services of 2023

Ubuntu 22.04 LTS is available for download. What is new?

CERN and Fermilab recommend AlmaLinux

7 best hosting control panels of 2023

How to update Linux Kernel without rebooting?

7 best Linux mail servers of 2023

7 best cPanel alternatives for 2023

7 best Linux web browsers for 2023

7 best CentOS alternatives

7 best Linux server distros of 2023

Interview with Igor Seletskiy on AlmaLinux

How to create a VM on VMware Workstation

Recent News

  • New local privilege escalation vulnerability strikes X.Org server
  • Red Hat brings new security capabilities to Red Hat OpenShift
  • With BuddyPress 12.0, BP Rewrites will support backward compatibility
  • Dell to lay off 6,650 employees
  • Canonical joins the Academy Software Foundation

Cloud7 News
Cloud7 is a news source that publishes the latest news, reviews, comparisons, opinions, and exclusive interviews to help tech users of high-experience levels in the IT industry.

EXPLORE

  • Web Hosting
  • Cloud Computing
  • Data Center
  • Cybersecurity
  • Linux
  • Network/Internet
  • Software
  • Hardware
  • How-Tos
  • Troubleshooting

RESOURCES

  • Events
  • Interviews
  • Jobs
  • Opinion
  • Whitepapers
  • Glossary
  • Community Forum
  • Web Hosting Directory

Get the Cloud7 Newsletter

Get FREE daily newsletters from Cloud7 delivering the latest news and reviews.

  • About
  • Privacy & Policy
  • Copyright Policy
  • Contact

© 2023, Cloud7 News. All rights reserved.

No Result
View All Result
  • Cloud Computing
  • Web Hosting
  • Data Center
  • Linux
  • Cybersecurity
  • More
    • Network/Internet
    • Windows
    • Software
    • Hardware
    • Blockchain
    • Policy/Legislation
    • How-Tos
    • Troubleshooting
  • Events
  • Interviews
  • Jobs
  • Opinion
  • Whitepapers
  • Glossary
  • Community Forum
  • Web Hosting Directory

© 2023, Cloud7 News. All rights reserved.

Welcome Back!

Sign In with Facebook
Sign In with Google
Sign In with Linked In
OR

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Sign Up with Facebook
Sign Up with Google
Sign Up with Linked In
OR

Fill the forms below to register

*By registering into our website, you agree to the Terms & Conditions and Privacy Policy.
All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.