Linux Commands Examples

A great documentation place for Linux commands


renames multiple files

see also : mv - perl


rename-v ] [ -n ] [ -f ] perlexprfiles ]

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!



How to rename a file by replacing specific letters in the file in linux

Debian rename allows you to specify a sed substitution pattern to apply against filenames in order to rename them.


Batch rename files in Linux

Basically, you can use the rename tool for that. It should come in a Perl-based version with Debian-based Linux distros, but you can easily download it from source as well (obviously, you need to make it executable first with chmod +x).

The following command will replace the _full part with _500 on all JPG files in the current directory.

rename 's/_full/_500/' *.jpg

To do this recursively, starting from your current directory, use rename with find.

find . -type f -iname "*.jpg" -exec rename 's/_full/_500/' {} \;

Note: You may want to test the command before actually executing is. In order to do that, add the -n option to rename (e.g. between rename and the 's//' string).


Sort and rename images by date in EXIF info

Try this free product: AmoK Exif Sorter.


Is there a linux command like mv but with regex?

rename may be for you. The one on my system (Ubuntu Linux) is a Perl script which takes regular expressions.


Linux: rename file but keep extension?

There are no filename extensions in Linux.

Use regular expressions to cut particular substrings from the filename and access them.


Real-life scenario: you are extracting html from a chm file. Filenames in Windows are case-insensitive, so in Linux you'll get broken links. You have a file named index.HTML, but href="index.html" in URLs. So your goal is to adapt filenames to match links to them.

Assume you have the filename in a variable:


Starting with version 3.0 bash supports regular expressions itself, so you don't need any additional tools like grep/sed/perl etc to perform string manipulation. The following example illustrates the replacement of a back-end match in a string:

echo ${FILENAME/%\.HTML/.html}

The match and replacement strings can be parametrized if you wish, this provides additional flexibility when writing script. The following code snippet achieves the same goal:

echo ${FILENAME/%$match/$replacement}

Consult the bash docs for additional info.


Recursively rename files (change extension) in Linux

Something like:

find . -name '*.andnav' -exec sh -c 'mv "$0" "${0%.andnav}.tile"' {} \;

Rename photos during download from camera - on Linux?

sorry if I'll tell you something that could be obvious, but: have you tried if that application can run under WINE?

Just because I saw the website of cam2pc and it has a lot of features that, for sure, could be reproducted on any Unix machine, using many little tools (for example cron, wget, diff, mkdir, mv and so on), but it requires to have some skills and/or a little of spare time.

While I'm here, I would suggest you to take a look at DigiKam and at F-Spot as well that, although don't have all the features you are requiring, maybe could help you to do some useful tricks.

Hope that helps.

EDIT: I tried cam2pc inside my box (Ubuntu 9.04 64bit) under WINE and it worked like a charm! Here's a screenshot where you can see my desktop with cam2pc running and a terminal with the outputs of uname -a and wine --version:

enter image description here


Renaming files in batch with Unix RENAME

rename doesn't do sed-style substitutions. This very short Perl script will let you do regmv *.sam s/indel/snp/:

#!/usr/bin/perl -w
# regmv - Rename files using a regular expression
# This program renames files by using a regular expression to
# determine their new name.
# Usage: regmv file [file ...] regexp
# $Id: regmv,v 1.1 1998/10/14 17:07:55 blrfl Exp $

sub at_clean()
    my $message = $@;
    $message =~ s|\s+at /.*$||s;
    return $message;

(@ARGV > 1)
    || die "Usage: regmv [options] file [file ...] regexp\n";

my $expr = pop @ARGV;

$_ = 'SomeValue';
eval "\$_ =~ $expr";
die "Yuck: " . at_clean() if $@;

foreach (@ARGV)
    my $old = $_;

    eval "\$_ =~ $expr";

    next if $_ eq $old;

    (rename $old, $_)
        || die "Rename failed: $!\n";

How to recursively rename files/folders to make their names Windows-friendly?

Take a look at Glindra rename and detox.

Source: Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems


Rename images so they burn to CD in order

For reordering by date, see here ("Rename a JPG by timestamp only"). Got that via Googling "rename jpeg exif linux".


"rename" renames the filenames supplied according to the rule specified as the first argument. The perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input.

For example, to rename all files matching "*.bak" to strip the extension, you might say

        rename 's/\.bak$//' *.bak

To translate uppercase names to lower, you’d use

        rename 'y/A-Z/a-z/' *


-v, --verbose

Verbose: print names of files successfully renamed.

-n, --no-act

No Action: show what files would have been renamed.

-f, --force

Force: overwrite existing files.


If you give an invalid Perl expression you’ll get a syntax error.


No environment variables are used.


The original "rename" did not check for the existence of target filenames, so had to be used with care. I hope I’ve fixed that (Robin Barker).

see also

mv , perl


Larry Wall

How can this site be more helpful to YOU ?

give  feedback