Linux Commands Examples

A great documentation place for Linux commands

rename

renames multiple files


see also : mv - perl

Synopsis

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!

examples

5
source

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.

1
source

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).

1
source

Sort and rename images by date in EXIF info

Try this free product: AmoK Exif Sorter.

0
source

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.

0
source

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.

Example:

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:

FILENAME='index.HTML'

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:

match='\.HTML'
replacement='.html'
echo ${FILENAME/%$match/$replacement}

Consult the bash docs for additional info.

0
source

Recursively rename files (change extension) in Linux

Something like:

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

0
source

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

0
source

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";
}

0
source

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

0
source

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".

description

"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/' *

options

-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.

diagnostics

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

environment

No environment variables are used.


bugs

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


author

Larry Wall

How can this site be more helpful to YOU ?


give  feedback