Linux change extension all files

Linux Rename Multiple Files Extension

Linux Tutorials

We can use mv command to change the file name. We can use it to change the file extension too. But, it works with a single file only and it doesn’t take wild characters.

We can create a shell script to change the extension of multiple files at once.

Linux Shell Script to Change Extension of Multiple Files

Let’s look at the script code where we will use the mv command in a for loop to change the extension of all the files in the current directory.

Usage: multimove.sh doc txt (to change all .doc to .txt)

Testing the Rename Shell Script

Below is the sample output from the above program execution.

Script Assumptions and Limitations

  1. The files have only one period (.)
  2. It loops through all files in the current directory only. However, you can extend it to look for files in the child directories also.
  3. Whitespaces in the file name can cause a problem with the script. It has worked on my system with filenames having spaces but I can’t guarantee that it will work for you too.

Further Readings: Linux mv command

Crontab example — every 5 minutes

I love Open Source technologies and writing about my experience about them is my passion.

Leave a Reply Cancel reply

Newsletter for You

JournalDev is one of the most popular websites for Java, Python, Android, and related technical articles. Our tutorials are regularly updated, error-free, and complete. Every month millions of developers like you visit JournalDev to read our tutorials.

JournalDev was founded by Pankaj Kumar in 2010 to share his experience and learnings with the whole world. He loves Open source technologies and writing on JournalDev has become his passion.

Источник

HowTo: Unix / Linux Rename File Extension From .OLD to .NEW

To rename a file called resume.docz to resume.doc, run:

To rename file extension from .txt to .doc, enter:

To fix the extension of all your .txt files, enter::

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

The above command will rename all *.txt files to *.doc i.e. fix the extension of your txt files.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

How to rename multiple file with a single cmd …

“rename .txt .doc *.txt” was great command . Thank you

I have missed up my photos directory,
how can I rename all files
07.jpg.13 07.jpg.14 07.jpg.15 ……..

to the correct format
07-13.jpg 07-14.jpg 07-15.jpg …..

Источник

How to change the default application for a type of file on Linux

This howto explains how to change the default program to open all files with a given extension on Linux Mint, Ubuntu, Debian, and most Linux distributions. It also details how to change the default application for a batch of filetypes, for example all audio files or all video files.

Set the default program for a given filetype

1. In Nemo / Nautilus / Caja, right-click on any file with the desired file type or extension, choose “Properties” from the context menu.

2. The “Properties” dialog appears. Click on the “Open With” tab.

3. Select the desired application for the given filetype. All files with the same extension will now be opened with this program by default.

On Linux Mint, replace step one and two choosing “Open With” → “Other Application…” in the contextual menu, as seen in the picture above.

Change the default app for multiple filetypes

Changing the default application for one type of file is really easy, while changing a batch of file type associations reveals a little clumsier, but extremely efficient.

These instructions should work with a large spectrum of Linux flavours, please share your experience with your favorite distribution in the comments.

Associate all audio and video files to VLC instead of Totem media player (Movie Player)

Video files: .avi .mp4 .mpg .ogv .ogm .mkv .wmv etc.
Audo files: .mp3 .ogg .flac .wav .wma etc.

Open defaults.list with gedit:
gksudo gedit /usr/share/applications/defaults.list

And replace all occurrences of totem with banshee/rythmbox/vlc or the media player of your choice.
(Search → Replace → Replace All)

Save the modified file, and you’re done! Change are effective immediately.

Associate all office documents to LibreOffice instead of OpenOffice.org or Abiword

Office files: .odt .ods. .doc .docx .xls .xlsx etc.

Open defaults.list with gedit:
gksudo gedit /usr/share/applications/defaults.list

And replace all occurences of “openoffice.org” with “libreoffice”.
(Search → Replace → Replace All)

Finally, save the file. No need to restart, you’re all set!

Other file associations

Use the same technique to change the default application for all kind of file types or extensions, for example:

  • all pictures (.jpg, .png, .gif, etc.) should open up with gThumb instead of EOG/Eye of Gnome/Image Viewer
  • all html documents should open with Firefox instead of Chrome
  • all pdf files should open with Adobe Reader instead of Evince/Document Viewer.

Different solution for some Ubuntu versions

For an obscure reason, changing the file associations directly in the defaults.list doesn’t seem to work on some Ubuntu versions. Nevertheless, importing information to the the mimeapps.list works.

The file associations for each user are stored in:

In Ubuntu this file is almost empty. Let’s import informations from
/usr/share/applications/defaults.list

Display all the video MIME types / Media types associations with this command:
cat /usr/share/applications/defaults.list | grep video

Append all the lines containing video types to the local file:
cat /usr/share/applications/defaults.list | grep video >>

Open defaults.list with gedit:
gedit

And replace all occurrences of totem with vlc (Search → Replace…) Proceed similarly for audio files if needed. Unlike the standard method described at the beginning of this article, this method permits to assign a separate program to audio or to video files.

By Johannes Eva, January 2011 – November 2019

This article has been linked on LXer.com, Linux Today and some more…

  • How to install LibreOffice 7.2 on Linux Mint,… This article describes how to install LibreOffice 7.2 on Debian/Ubuntu-based Linux distributions, such as Linux Mint,…
  • Multimedia, codecs, MP3 & DVD support on CentOS,… This tutorial details how to install full multimedia support, media codecs, MP3 & DVD support on…
  • Sudo on CentOS / Scientific Linux / RHEL This short howto is about setting up sudo on Red Hat Entreprise Linux and its derivates…
  • Install VirtualBox on CentOS / RHEL / Scientific Linux This how-to is about installing VirtualBox on CentOS. Provided instructions should also work on Scientific Linux…
  • Install Flash Player directly from Adobe on Linux… Adobe Flash Player freezes constantly on my Ubuntu installation, sometimes crashing Firefox. Most of the time…
  • How to edit image metadata on Linux Image metadata is a complex field with multiple standards, the most important among them being Exif,…
  • How to Sync Fonts Between Linux Devices This small guide is about syncing fonts between two or more Linux devices, for example one…

3 Comments

I have .wma audio files showing as text files. It doesn’t help to use “open with” a media player because Mint thinks they’re text docs so nothing happens. Weirdly, one song in one folder IS still an audio file – and plays fine. Is there a global way to wipe out file associations and then re-associate via terminal?

In my Debian Jessie system, the per user settings are at: $HOME/.config/mimeapps.list

Helped me setting PDF files to be opened with Atril instead of Gimp (Ubuntu MATE 14.04). Thank you.

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Источник

6 Methods To Rename Multiple Files At Once In Linux

In this tutorial, we will learn how to rename multiple files at once in Linux using various tools. All examples provided here are tested in Ubuntu 18.04 LTS, however they should work on any Linux operating systems.

Introduction

As you may already know, we use mv command to bulk rename or move files and directories in Linux and Unix-like operating systems.

But, the mv command won’t support renaming multiple files at once. It can rename only one file at a time. What would you do if you wanted to rename multiple files at a time? Worry not!

There are a few other utilities available for batch renaming files in Linux.

Rename multiple files at once in Linux

There could be many commands and utilities to a rename bunch of files. As of writing this, I know the following methods only. I will keep updating the list if I come across any new method in future.

Method 1 — Using mmv

The mmv utility is used to move, copy, append and rename files in bulk using standard wildcards in Linux and Unix-like operating systems. It is available in the default repositories of Debian-based systems.

To install mmv on Debian, Ubuntu, Linux Mint, and Pop OS, run the following command:

Let us say, you have the following files in your current directory.

Now you want to rename all files that starts with letter «a» to «b» . Of course, you can do this manually in few seconds.

But just think if you have hundreds of files and want to rename them? It is quite time consuming process. Here is where mmv command comes in help.

To rename all files starting with letter «a» to «b» , simply run:

Let us check if the files have been renamed or not.

As you can see, all files starts with letter «a» (i.e a1.txt , a2.txt , a3.txt ) are renamed to b1.txt , b2.txt , b3.txt .

Explanation

In the above example, the first parameter ( a* ) is the ‘from’ pattern and the second parameter is ‘to’ pattern ( b#1 ).

As per the above example, mmv will look for any filenames staring with letter ‘a’ and rename the matched files according to second parameter i.e ‘to’ pattern.

We use wildcards, such as ‘*’ , ‘?’ and ‘[]‘ , to match one or more arbitrary characters. Please be mindful that you must escape the wildcard characters, otherwise they will be expanded by the shell and mmv won’t understand them.

The ‘#1′ in the ‘to’ pattern is a wildcard index. It matches the first wildcard found in the ‘from’ pattern. A ‘#2′ in the ‘to’ pattern would match the second wildcard and so on.

In our example, we have only one wildcard (the asterisk), so we write a #1 . And, the hash sign should be escaped as well. Also, you can enclose the patterns with quotes too.

You can even rename all files with a certain extension to a different extension. For example, to rename all .txt files to .doc file format in the current directory, simply run:

Here is an another example. Let us say you have the following files.

You want to replace the the first occurrence of abc with xyz in all files in the current directory. How would you do?

Please note that in the above example, I have enclosed the patterns in single quotes.

Let us check if «abc» is actually replaced with «xyz» or not.

See? The files abcd1.txt, abcd2.txt, and abcd3.txt have been renamed to xyzd1.txt, xyzd2.txt, and xyzd3.txt.

Another notable feature of mmv command is you can just print output instead of renaming the files using -n option like below.

This way you can simply verify what mmv command would actually do before renaming the files.

For more details, refer man pages.

Method 2 — Using rename utility

The rename utility will rename given files by substituting the first occurrence of expression in their name by replacement.

The rename command comes preinstalled in most Unix-like operating systems. If it is not available by default, run the following command to install it on Debian-based systems:

For instance, I have the following files in the current directory.

Let us replace the the first occurrence of abc with xyz wherever found. To do so, run:

Now, verify if the changes have been made with ls command.

Sometimes, you might to just print output instead of renaming the files. If so, use -n flag to display which renames would occur without performing them:

As you can see, the above command didn’t make any changes, instead just displays which renames would occur.

You can force renaming task even if the operation would overwrite existing files using -f flag like below.

If you don’t want to overwrite the files, you can simply convert them to upper or lowercase letters (and vice versa) to prevent «already exists» errors.

To convert all filenames to lower case, so:

Let us check if the changes have been made.

Yes, the letters in the filenames have been changed from lower case to upper case.

Similarly, to convert filenames to lower case, run:

We can remove all blank lines in a filename as well. For example, I have the following file.

To remove all blank spaces in the above filename, run:

Now, the filename doesn’t have any blank spaces.

Replace blank spaces with underscores:

You might want to change the file extension, but not rename the filenames. It is also possible. The following command would rename all *.txt files to *.doc .

Verify the changes using ls command:

To remove extension in all files matching .txt, run:

For more details, refer man pages.

Method 3 — Using renameutils

The renameutils is a set of programs that is designed to batch renaming files and directories faster and easier.

Renameutils consists of the following five programs:

  1. qmv (quick move),
  2. qcp (quick copy),
  3. imv (interactive move),
  4. icp (interactive copy),
  5. deurlname (delete URL).

Install renameutils in Linux

Renameutils is available in the default repositories of most Linux distributions. To install it on Arch-based systems, enable the community repository and run:

On Debian-based systems:

Now, let us see some examples.

1. qmv

The qmv program will open the filenames in a directory in your default text editor and allows you to edit them.

I have the following three files in a directory named ‘ostechnix’.

To rename the filenames in the ‘ostechnix’ directory, simply do:

Now, change the filenames as you wish. You will see the live preview as you edit the filenames.

Alternatively, you can cd into the directory and simply run ‘qmv’ .

Once you opened the files, you will see the two columns as shown in the following screenshot.

The left column side displays the source filenames and the right column displays the destination names (the output filenames that you will get after editing).

Now, rename all the output names on the right side as you wish.

After renaming filenames, save and quit the file.

Finally, you will see the following output:

Now, check if the changes have actually been made using ‘ls’ command:

See? All files are renamed. Not just files, the renameutils will also rename the directory names as well.

Here is a quick video demo of qmv program:

If you don’t want to edit the filenames in dual-column format, use the following command to display the destination file column only.

Where, ‘-f’ refers the format and ‘do’ refers destination-only .

Now, you will see only the destination column. That’s the column we make the changes.

Once done, save and close the file.

For more details, refer man pages.

2. qcp

The qcp program works like qmv, but copies files instead of renaming them. In this case, you will get two instances of same file. That means it will keep both original and duplicate files.

Rename the filenames listed on the right side. Save and quit the file. Finally, verify the changes made using ls command:

For more details, refer man pages.

3. imv

The imv program allows us to interactively rename the filenames. Obviously, it is not for bulk renaming. You could only rename the files one by one.

Edit the filename as you like and hit ENTER to rename it.

For more details, refer man pages.

4. icp

The icp program is same as imv , but it copies the files instead of moving them.

For more use cases and commands, please refer man pages.

I don’t know why the developers added these two utilities while we can do the same using mv and cp command.

5. deurlname

The deurlname program removes URL encoded characters (such as %20 representing space) from file names. Some programs, for examples w3m, tend to keep those characters encoded in saved files.

You can this tool for cleaning up the filenames you downloaded from the Internet.

Take a look the the following file.

There are some special characters and numbers in the filename. If you clean it up, just run:

Now, look how the file name is changed.

The filename is clean and readable.

Refer man pages for more details.

Also, refer the project’s website given at the end of this guide.

Method 4 — Using vimv

As the name says, Vimv is a command line utility to bulk rename files using Vim editor. You can, of course, change the editor by changing the value of $EDITOR environment variable.

To install Vimv, git clone the repository:

Copy the vimv binary to your $PATH , for example /usr/local/bin/ .

Finally, make it executable:

Now go to the directory and run the following command to edit the filenames.

You will see the filenames in Vi editor. Press i to switch to interactive mode and edit the filenames as the way you edit text in Vi editor. Once done, press ESC key and type :wq to save and exit.

The files inside the directory should be renamed now. Here is a short video demo.

For more details, refer the project’s GitHub repository given at the end of this guide.

Method 5 — Using Emacs

If you have a system with Emacs editor installed, you can do batch renaming easily by following these steps.

1. Open your Emacs editor.

2. Press Alt+x and type the following and hit ENTER to switch to wdired-mode (short for «writable directory editor mode»).

3. Enter the path to the directory (E.g. /home/sk/ostechnix ) which contains the files to rename and hit ENTER key.

4. Then, press Ctrl+x and Ctrl+q to switch to read-write mode.

5. Now, rename the files. Once done, press Ctrl+c and Ctrl+c (two times) to save the changes. To abort the changes, press Ctrl+c and Ctrl+k .

Watch the demo video:

See? It is very simple to rename multiple files at once.

Method 6 — Using Thunar file manager

The Thunar file manager has built-in bulk rename option by default.

Thunar is available in the default repositories of most Linux distributions.

To install it on Arch-based systems, run:

On Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux:

On Debian, Ubuntu, Linux Mint:

Once installed, you can launch bulk rename utility from menu or from the application launcher. To launch it from Terminal, use the following command:

This is how bulk rename looks like.

Click the plus sign and choose the list of files you want to rename. Bulk rename can rename the name of the files, the suffix of the files or both the name and the suffix of the files.

Thunar currently supports the following Bulk Renamers:

  • Insert Date or Time
  • Insert or Overwrite
  • Numbering
  • Remove Characters
  • Search & Replace
  • Uppercase / Lowercase

When you select one of these criteria from the picklist, you will see a preview of your changes in the New Name column, as shown in the below screenshot.

Once you choose the criteria, click on Rename Files option to rename the files.

You can also open bulk renamer from within Thunar by selecting two or more files. After choosing the files, press F2 or right click and choose Rename .

Suggested read:

And, that’s all for now. Hope this was useful. Do you know any other method to add in this list? Please mention them in the comment section below. I will check and update this guide accordingly.

Источник

Читайте также:  Windows loader не помог
Оцените статью