www.unixmen.com Open in urlscan Pro
2606:4700:20::ac43:4608  Public Scan

Submitted URL: http://www.unixmen.com/how-to-rename-files-in-unix-linux/
Effective URL: https://www.unixmen.com/how-to-rename-files-in-unix-linux/
Submission: On June 14 via manual from US — Scanned from US

Form analysis 2 forms found in the DOM

GET https://www.unixmen.com/

<form method="get" class="td-search-form" action="https://www.unixmen.com/">
  <div class="td-search-close w3_bg"> <a href="#"><i class="td-icon-close-mobile"></i></a></div>
  <div role="search" class="td-search-input w3_bg"> <span>Search</span> <input id="td-header-search-mob" type="text" value="" name="s" autocomplete="off"></div>
</form>

GET https://www.unixmen.com/

<form method="get" class="td-search-form" action="https://www.unixmen.com/">
  <div role="search" class="td-head-form-search-wrap w3_bg"> <input id="td-header-search" type="text" value="" name="s" autocomplete="off"><input class="wpb_button wpb_btn-inverse btn" type="submit" id="td-header-search-top" value="Search"></div>
</form>

Text Content

 * Home
 * Linux distributions
 * Linux tutorials
 * News
 * Frequently Asked Questions
 * Opensource
 * Unix
 * Linux HowTo’s
 * Linux Distro’s
 * Linux & Open Source News
 * Contact Us


Search

Wednesday, June 14, 2023
 * About Us
 * Advertising on Unixmen
 * Become a Contributor
 * Unixmen collaborated with Unixstickers
 * Contact Us

Unixmen

 * Home
 * Linux distributions
 * Linux tutorials
 * News
 * Frequently Asked Questions
 * Opensource
 * Unix
 * Linux HowTo’s
 * Linux Distro’s
 * Linux & Open Source News
 * Contact Us




Home Linux tutorials How to rename files in UNIX / Linux


HOW TO RENAME FILES IN UNIX / LINUX

By
Winnie Ondara
Share on Facebook
Tweet on Twitter
 * 
 * tweet

As a UNIX user, one of the basic tasks that you will often find yourself
performing is renaming files and folders. Renaming a file is quite elementary
and really shouldn’t be an uphill task. You can rename a file or directory in
UNIX from a terminal (CLI) or using third-party tools (GUI tools).
In this guide, we will discuss two command-line tools that you can use to rename
files in UNIX.


RENAME FILES IN UNIX USING THE MV COMMAND

Short for ‘move’ the mv command is a command that is used primarily to move
files and folder from one location to another. However, it can also be used to
rename a file.


MY LATEST VIDEOS


video_2021_01_08_10_41_24

More Videos


0 seconds of 1 minute, 13 secondsVolume 0%

Press shift question mark to access a list of keyboard shortcuts
Keyboard ShortcutsEnabledDisabled
Play/PauseSPACE
Increase Volume↑
Decrease Volume↓
Seek Forward→
Seek Backward←
Captions On/Offc
Fullscreen/Exit Fullscreenf
Mute/Unmutem
Seek %0-9
Next Up
Setting Up DNS Server On CentOS7 (2)
02:45
Auto540p720p540p360p270p180p
Live
00:20
00:53
01:14







 

The syntax for renaming a file using the mv command is shown below:

 $ mv (option) filename1 filename2 

In the command above,

filename1
is the original file while
filename2
is the new name that the file will take. If the file to be renamed is not
located in the current directory, be sure to specify the full path of the file.



Let’s take an example as shown in the command below:




$ mv  /home/sales.txt /home/marketing.txt

The command renames the file

sales.txt
located in the home directory to
marketing.txt

NOTE:

When the file is not located in the current folder, the complete file path to
the file and the new file name should be specified. If the path of the file
differs from the path of the new filename, the file will be moved to the new
file path and later on renamed.

For example:

$ mv  /home/sales.txt /home/data/marketing.txt

In the above example, the

sales.txt
file is moved entirely from the home directory to the /home/data path and
renamed
marketing.txt

.This is a cool way of killing two birds at the same time – moving and renaming
files. However, if your sole goal is to rename the file, ensure the file paths
in both instances match without any variations.



The mv command can be used with a variety of options. For example to print the
verbose output of the command, use the

-v
option as shown.



$ mv -v  sales.txt marketing.txt


RENAMING A DIRECTORY

Renaming a directory also follows the same syntax as renaming a file, i.e.



$ mv directory_name1 directory_name2

For example, to rename a directory called


python_docs
to
django_docs
in the current working space run the command:



$ mv python_docs django_docs


RENAME FILES IN UNIX USING THE RENAME COMMAND

So far we have looked at how to rename files and directories using the

mv
command. Quite a straightforward task right? However, a challenge presents
itself when renaming multiple files and folders at a go. Things get a little
tricky and in that case, you may be required to use some bash scripts or loops
to achieve your goal. In that scenario, the
mv

command will not be of much help.



This is where the

rename
command comes in. The command comes in handy when renaming bulk. The command
replaces the search expression contained in the file with another expression
provided for by the user.




INSTALLING RENAME

Modern Linux distributions ship with rename command by default. However, if you
are running an older Linux distribution, here is how you to install it:

For Debian and Ubuntu systems, run the command:

$ sudo apt update

 $ sudo apt-get install rename 

For CentOS, Fedora and RHEL, execute:



 $ sudo dnf install prename 

Notice the ‘p’ that precedes the rename command. The ‘p’ stands for Perl.



For Arch / Manjaro systems run:

 $ sudo pacman -Syu perl-rename 


USING RENAME COMMAND

As earlier stated, the rename command is used for renaming a batch of files,
more specifically changing the file extension of multiple files simultaneously.

To better demonstrate how the command works, we have 5 text files all with a
‘.txt’ file extension as shown.

The following command is going to convert all the .txt files to .pdf files



$ rename 's/.txt/.pdf/' *.txt

You can confirm that the files have been renamed using the good-old

ls

command as shown. And true to your expectations, the file extensions will have
been renamed.



Let’s break down the command:

‘s/…/…/’ – This is the substitution operator. The first argument is the search
term and the second argument is the replacement.

.txt – This represents the search term. The rename command will scour for this
pattern in all files in the directory and thereafter replace it with the second
argument

.pdf – This is the replacement option that will replace the pattern in the first
argument.



*.txt – The use of the wildcard symbol instructs the rename command to search
for all instances with the pattern .txt

If you are not sure which files will be affected, you might need to perform a
dry run before proceeding with the operation.



To achieve this, use the -n option as shown

 $ rename -n 's/.txt/.pdf/' *.txt 

To view the verbose output as files are being renamed, use the -v option as
shown.

$ rename -v 's/.txt/.pdf/' *.txt

And this brings us to the end of this topic on how to rename files in UNIX.
Renaming files is part of the basic commands that every Linux user should have
at their fingertips. We hope that you can comfortably rename your files and
directories without much of an issue. Give us a shout and let us know if you are
having any difficulties.



Winnie Ondara

EDITOR PICKS


VISUAL DATABASE DESIGN – WITH ORACLE DATABASE DESIGNER

Linux HowTo's Janus Atienza - June 12, 2023
0


EXPLORING THE POWER OF TRACKER APPLICATIONS ON ANDROID: LEVERAGING THE LINUX
FOUNDATION

Linux HowTo's June 1, 2023


UNLOCKING THE POWER OF UNIX: A GUIDE FOR ASPIRING BLOGGERS AND WRITERS

Tips & Tricks May 29, 2023


5 MAJOR BENEFITS OF HAVING A MANAGED SECURITY SERVICES PROVIDER (MSSP) FOR UNIX
AND LINUX

Linux HowTo's May 28, 2023


REVOLUTIONIZING VIDEO MAKING WITH LINUX: UNLEASHING CREATIVE POTENTIAL

Linux HowTo's May 28, 2023



FOLLOW US


0FansLike

0FollowersFollow

12,304FollowersFollow

528SubscribersSubscribe

LATEST ARTICLES


VISUAL DATABASE DESIGN – WITH ORACLE DATABASE DESIGNER

Linux HowTo's Janus Atienza - June 12, 2023
0
Mastering database design with Oracle Database Designer Oracle Database Designer
is a data modeling tool that allows users to create, modify and manage database
models...


EXPLORING THE POWER OF TRACKER APPLICATIONS ON ANDROID: LEVERAGING THE LINUX
FOUNDATION

Linux HowTo's Janus Atienza - June 1, 2023
0
Welcome to the world of tracker applications on the Android operating system.  A
tracker application, in its simplest form, is a software program designed...


UNLOCKING THE POWER OF UNIX: A GUIDE FOR ASPIRING BLOGGERS AND WRITERS

Tips & Tricks Janus Atienza - May 29, 2023
0
Writing and blogging have become two of the most well-liked pastimes on the web.
However, you'll need to be inventive and unique if you...


5 MAJOR BENEFITS OF HAVING A MANAGED SECURITY SERVICES PROVIDER (MSSP) FOR UNIX
AND...

Linux HowTo's Janus Atienza - May 28, 2023
0
The annual security breaches for Unix and Linux infrastructure is at an all-time
high, with almost 1.7 million Linux malware floating across the internet...


REVOLUTIONIZING VIDEO MAKING WITH LINUX: UNLEASHING CREATIVE POTENTIAL

Linux HowTo's Janus Atienza - May 28, 2023
0
In today's digital age, videos have become an integral part of our lives. From
social media platforms to professional presentations, videos have the power...

POPULAR POST


CentOS


EVERYTHING YOU SHOULD KNOW ABOUT RHCSA CERTIFICATION

Rajneesh Upadhyay - March 29, 2016
6
Things you should know about RHCSA Certification Exam RHCSA or Red Hat Certified
System administration exam is designed to test your knowledge and skills
which...


‘IFCONFIG’ COMMAND NOT FOUND IN CENTOS 7 MINIMAL INSTALLATION – A...

CentOS August 11, 2014


HOW TO INSTALL UNIVENTION CORPORATE SERVER

Linux tutorials December 25, 2015


TOP THINGS TO DO AFTER INSTALLING UBUNTU 15.04

Linux distributions April 22, 2015


HOW TO BLOCK ACCESS OF USB AND CD/DVD IN DEBIAN AND...

Frequently Asked Questions March 30, 2016

RELATED POSTS


Software


BANSHEE 1.9.6 IS RELEASED!

Roy s - March 24, 2011
0
Banshee 1.9.6  is released, this is a  development release, part of the 1.9
series leading up to Banshee 2.0.       What`s new in this beta release? ...


MONITOR LINUX SERVER WITH NAGIOS CORE USING SNMP

Linux distributions July 14, 2015


KDE SHIPS APRIL UPDATES TO APPLICATIONS

Announcements April 2, 2014


INSTALL HOTSHOTS 2.1.0 IN LINUX MINT, ELEMENTARY OS, UBUNTU

Linux distributions February 22, 2014


GRUB CUSTOMIZER 2.5.5 IS AVAILABLE- CUSTOMIZE GRUB/BURG FROM A GUI INTERFACE

Linux distributions May 10, 2012


FOLLOW US


0FansLike

0FollowersFollow

3,500FollowersFollow

12,304FollowersFollow

528SubscribersSubscribe

LATEST ARTICLES


VISUAL DATABASE DESIGN – WITH ORACLE DATABASE DESIGNER

Linux HowTo's Janus Atienza - June 12, 2023
0
Mastering database design with Oracle Database Designer Oracle Database Designer
is a data modeling tool that allows users to create, modify and manage database
models...


EXPLORING THE POWER OF TRACKER APPLICATIONS ON ANDROID: LEVERAGING THE LINUX
FOUNDATION

Linux HowTo's Janus Atienza - June 1, 2023
0
Welcome to the world of tracker applications on the Android operating system.  A
tracker application, in its simplest form, is a software program designed...


UNLOCKING THE POWER OF UNIX: A GUIDE FOR ASPIRING BLOGGERS AND WRITERS

Tips & Tricks Janus Atienza - May 29, 2023
0
Writing and blogging have become two of the most well-liked pastimes on the web.
However, you'll need to be inventive and unique if you...


ABOUT US
Unixmen provide Linux Howtos, Tutorials, Tips & Tricks ,Opensource News. It
cover most popular distros like Ubuntu, LinuxMint, Fedora, Centos. It is your
Gate to the the world of Linux/Unix and Opensource in General.

Privacy Policy Cookie Policy Advertise
© Copyright 2020 - Newspaper 6 by TagDiv
Edit with Live CSS


Save
Write CSS OR LESS and hit save. CTRL + SPACE for auto-complete.

✕
Do Not Sell Or Share My Personal Information
You have chosen to opt-out of the sale or sharing of your information from this
site and any of its affiliates. To opt back in please click the "Customize my ad
experience" link.

This site collects information through the use of cookies and other tracking
tools. Cookies and these tools do not contain any information that personally
identifies a user, but personal information that would be stored about you may
be linked to the information stored in and obtained from them. This information
would be used and shared for Analytics, Ad Serving, Interest Based Advertising,
among other purposes.

For more information please visit this site's Privacy Policy.
CANCEL
CONTINUE

Information from your device can be used to personalize your ad experience.

Do not sell or share my personal information.
A Raptive Partner Site