1

I have some files inside a folder like this:

DUMAK011.618
DUMAK011.619
DUMAK011.620

I would like to rename them to:

DUMAI011.618
DUMAI011.619
DUMAI011.620

2 Answers 2

3

This can be achieved in Bash with a one-liner:

for i in DUMAK011.6*; do mv "$i" "DUMAI${i##DUMAK}" ;done
1
  • 1
    If you use bash, this is a good tool to have in your toolbelt. It works for many other tasKs and doesn't need anything new installed on a system.
    – fuzzyTew
    Aug 9, 2021 at 11:26
2

You can do this with mmv (Multi-Move), so long as you install it first:

sudo apt install mmv

Once installed, you can do something like this:

mmv DUMAK\* DUMAI\#1

That will rename all files starting with DUMAK, leaving everything afterwards and the extension untouched. If you are proficient with shell glob patterns, you can save a remarkable amount of time with this tool.

If you'd like, you can learn more about the power of mmv from the documentation.

6
  • Thank you for this but since the file were recurrence/ downloaded everyday on the said folder, is it possible to have a bash script for this so the new files were automatically renamed once detected? Or this only possible by manual execution? Thank you so much in advance. Jul 28, 2021 at 5:01
  • You can certainly write a script that will automatically rename files if that's what you would like to do. The script could be executed at regular intervals via a cron job, as that would require fewer resources than having a file system watcher.
    – matigo
    Jul 28, 2021 at 5:08
  • On the given command line, it will only rename files starting with DUMAK. Forgot to mentioned but what if there is an other file that need to be rename as well, e.g HUMAK and SUMAK, can I rename those files in one execution (DUMAK, SUMAK and HUMAK)? Jul 28, 2021 at 5:41
  • 1
    So long as there is a predicable pattern, yes. Take a look at shell glob patterns and how they're expanded. That'll let you rename items accordingly.
    – matigo
    Jul 28, 2021 at 6:25
  • ... for example mmv -n '?UMAK*' '#1UMAI#2' or mmv -n '*MAK*' '#1MAI#2' Jul 28, 2021 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .