How to Rename File From Linux Command Line

Renaming files is one of the most fundamental tasks on a Linux system. On the command line, the mv (move) command is used not only to move files to different locations, but also to rename them.

In this tutorial, you will see how to use the mv command to rename files and folders on Linux. We’ll go through a few examples so you get the hang of it.

Renaming Files With mv Command

You can rename files by using the mv command. The syntax is as follows:

$ mv oldname newname

We can also use a simple for script to rename multiple files at once. For example, to change all files from .jpeg extension to .jpg:

$ for f in *.jpeg; do mv "$f" "${f%.jpeg}.jpg"; done

More examples: Rename Multiple Files at Once

Renaming File With cp Command

The cp command allows us to make a copy of a file. You can give the new file any name you want.

$ cp oldfile newfile

Note that this will create a new file with the name newfile. If you want to remove the source of the copy, you can execute the rm command to delete it:

$ rm oldfile

Leave a Comment

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