Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

Rename or Move Files or Directories in Linux with Bash Terminal

Posted on 29/10/202215/08/2026 Imoh Etuk By Imoh Etuk No Comments on Rename or Move Files or Directories in Linux with Bash Terminal
  1. Home
  2. Linux
  3. Rename or Move Files or Directories in Linux with Bash Terminal
MV-command-in-Linux

In this article, we shall discuss how to rename or Move Files or Directories in Linux with Bash Terminal. When it comes to working on the Linux OS renaming files and directories is a common daily task for a system administrator. It is a routine operation that can be carried out whether you are using the command line or the GUI. Please see How to install Windows Subsystem for Linux on Windows 11 via the Command line, and Microsoft Store, and how to get Domain information using WHOIS Command in Linux.

The CLI is a particularly potent tool when compared to the GUI (or Graphical User Interface). This is partially because you can rename files in bulk or even schedule the scripts to do it at a specific time.

See the following guides to learn more: How to fix SU authentication failure and Sudo Permission denied Prompt in Ubuntu, Linux Cheat Sheet: The Linux Command Line,

The CLI is a particularly potent tool when compared to the GUI (or Graphical User Interface). This is partly due to the fact that you can rename files in batch and or schedule the scripts to do it at a specific time.

Bash is a command generator that normally operates in a text window where users enter instructions to trigger operations Linux OS. A shell script is a file that contains commands that Bash can read and execute. Apart from having the rename or file moving command (mv), there are thousands of other Bash commands that are worth knowing as a system administrator.

If will like to read about Git, see the following guides: Git command not found: How to fix Git is not recognized as an internal or external command. Git Vulnerability: Git for Windows uninstaller is vulnerable to DLL hijacking when run under the SYSTEM user account.

What is BASH?

Bash stands for Bourne Again Shell. Computers provide two types of interfaces to the user Linux OS; that is, the Graphical User Interface (GUI), and text-based interfaces (through the command line or terminal). These interfaces allow you to navigate through the operating system and file system.

In text-based interfaces, a command line interpreter or shell is used to interpret the given commands by the user. Thus, allowing users to provide commands through which the user can specify what they want to do. Before providing the commands, bash displays a prompt, as you open the command line (in Linux and macOS), such as the one below.

user@localhost:~$

Renaming a File in Linux

In this section, you will learn how you can rename or move files in the Linux command line using the built-in mv command.

In Linux operating systems, the mv command moves and renames files and directories. You can use the built-in Linux command mv to rename files.

The mv command follows this syntax:

mv [options] source_file destination_file

For instance, in the screenshot below I created a directory called folder1 and folder2 with the mkdir command and later renamed folder2 to folder3.

To test if that really took effect, I navigated to folder1 with the cd command but got an error and later cd into folder3 and it worked Linux OS.

Linux operating system

While using the mv command below are some useful options:

-v , --verbose: Explains what is being done.
-i, --interactive: Prompts before renaming the file.

Another example is, let’s say you want to rename index.html to mywebsite_page.html. You use the mv command as shown below:

 $ mv index.html web_page.html
Linux platform

Renaming files extension in bulk using the mv command Linux OS

Having learned about renaming singles, let’s take a look at how to rename bulk files.

In thejsfiles directory, we have a bunch of .js files that we will like to rename in bulk.

Linux distribution

Next, we want to convert them to .json extensions. To do so, run the command below:

for f in *.js; do mv -- "$f" "${f%.js}.json"; done
Linux environment

Now let’s take brief look at this long command to see what it means:

The first part [for f in *.js] tells the for loop to process each “.js” file in the directory.
The next part [do mv -- "$f" "${f%.js}.json] specifies what the processing will do. It is using mv to rename each file. The new file is going to be named with the original file’s name excluding the .js part. A new extension of .json will be appended instead.
The last part [done] simply ends the loop once all the files have been processed.

Renaming using regular expressions Linux OS

mv does not interpret regular expressions (regex). If you want to rename many files using a complex or nuanced mapping from old to new file names, you use the rename command instead. rename accepts Perl regular expressions. For example Linux OS:

rename 's/My\ file(..)/newdocs$1/' My*

This command renames files My file.txt and My file 2.txt to newocs.txt and newdocs 2.txt.

Moving Files to a Directory using the mv command

The mv command is a powerful command as it can also be used to move files between directories.

Moving-a-file1

In the above screenshot, we created a file named text1.txt in the Desktop location and moved it to the myfiles directory.

Another example is if we move the file myfile.txt into the directory myfiles. If myfiles is a file, it is overwritten. If the file is marked as read-only but you own the file. You are prompted before overwriting it.

File-replacement

Another instance is if myfiles is a file or directory and myfiles1 is a directory, move myfiles into myfiles1. If myfiles1 does not exist, the file or directory myfiles is renamed myfiles1.

Replacing-files

Now let’s move the directory myfiles to the parent directory of the current directory Linux OS.

Move-files-to-the-parent-directory

In conclusion, renaming and moving files or directories is quite easy using the mv command. You can use it to perform a lot of powerful tasks on Linux.

I hope you found this article useful on how to rename or Move Files or Directories in Linux with Bash Terminal. Please feel free to leave a comment below.

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
Linux

Post navigation

Previous Post: How to enable Adblocker on Microsoft Edge
Next Post: How to Install and Use Minikube on a Linux System

Related Posts

  • feature linux boot process
    Linux Boot Process Explained Step by Step for Beginners Linux
  • FEATURE IMAGE BASE URL 1
    How to solve cannot find a valid base URL for repo: base/7/x86_64 Linux
  • cockpit
    Installation and configuration of Cockpit on CentOS Linux Linux
  • feature photo quit vim
    How to Exit Linux Vim or Vi Editor Linux
  • mailx
    [MAILX ERROR: STATUS=BOUNCED] Fixing Mailx error when sending emails from Command line Linux
  • screenshot 2020 05 05 at 22.42.35
    How to run Windows applications on Linux via WineHQ Linux

More Related Articles

posfix as an smtp server How to Install and Configure Postfix as a Send-Only SMTP Server Linux
dsdfg Create a Bootable USB Drive Using dd Command on Linux Linux
openshift Set up OpenShift Cluster using Red Hat CodeReady Containers Linux
runlevels How to check your current Runlevel in Linux Linux
prometheus feature image How to use Prometheus for Monitoring Linux
fba7f screenshot 2019 04 15 at 18.33.30 File System Overview: How to decide on the right File System to use for your USB Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

vexpert-badge-stars-5

Virtual Background

VEEAMLEGEND

Categories

Top 30 Sysadmin blog

veeaam100

Veeam Vanguard

  • Screenshot 2021 02 09 at 16.10.30
    Download and install Fujitsu DeskUpdate & DeskUpdate Manager Windows Server
  • Webp.net resizeimage 1
    Automate Infrastructure Deployments in the Cloud with Ansible and Azure Pipelines AWS/Azure/OpenShift
  • feature image sublime text 4
    How to install Sublime Text 4 on Ubuntu Linux
  • cb5e9fcbe91618c68c5236d801eb6721
    Real-Time Monitoring: How to setup VeeamONE Network | Monitoring
  • Featured image 6
    How to remove OneDrive from Windows Microsoft Exchange/Office/365
  • How to create blue screen using the Not my Fault tool from Sysinternals
    How to create blue screen using the Not my Fault tool from Sysinternals Windows
  • Snapshot
    Create or delete snapshots on VMware Workstation Backup
  • Protect OOTBI
    Best Storage for Veeam: Comparing OOTBI by ObjectFirst to VHR Backup

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,747 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Contact
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon
  • Bsky

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.