IgnorantGuru's Blog

Linux software, news, and tips

Script: sedname


Download Links:
Script: downloadbrowseauthenticateinstructions
Debian/Ubuntu: packagesPPA
Arch Linux: AUR
Description: Batch-renames files using a sed script
Recommended For: Linux
License: GNU GPL v3     * SEE DISCLAIMER *
Related: rmdupe
Feedback: commentsissues


sedname passes filenames through the sed stream editor using a sed script you specify, and renames the files to the result. If you are familiar with sed, sedname provides a familiar way to rename batches of files quickly. In addition, sedname can insert sequential numbers into the filenames to make them unique. It also supports a simulation mode which lets you see how files will be renamed without making any actual changes.

sedname --help
Batch-renames files using a sed script

Usage: sedname [OPTIONS] SEDSCRIPT FILE ...
Usage: find [...] | sedname [OPTIONS] SEDSCRIPT

Example: sedname 's/\(.*\)\.jpg/\1.jpeg/' *.jpg
Example: find /mypics | sedname 's/\(.*\)\.jpg/\1.jpeg/'

--sim           simulate only
--dir           rename directories too

Use #D to insert a number with D digits forming a unique filename
    Example: sedname 's/thisname.*/thatname#3/' *
    ( changes thisname* to thatname001, thatname002, ... )

Use #0 in replacement name to insert a number if needed
    Example: sedname 's/thisname.*/thatname#0/' *
    ( changes thisname* to thatname, thatname1, thatname2, ... )

sedname may be run by itself, passing the files on the command line. Or for greater flexibility and recursion, the output of any find command can be piped through sedname. Note that only the filename is passed through sed, not the full pathname of the file (sedname cannot move files to a different directory).

Include the ––sim option to run a simulation only. Note that if #D is used, the filenames in the simulation may not represent the actual result exactly, as earlier renames may result in different numbering.


Installation Instructions

Follow the standard Script Installation Instructions. Alternatively, for Debian and Ubuntu a deb package and a PPA repository are available. On Arch Linux, sedname can be installed automatically using the AUR.



  1. I think there’s a missing “-f” at line 115.
    It should be:

    rs=`echo “$rbase” | sed -f “$sedscript”`


    rs=$(echo “$rbase” | sed -f “$sedscript”)

    Comment by ColdFeetBob | March 3, 2012 | Reply

    • The sedscript variable is not a file, it is a string given on the command line. See ‘sedname ––help’ for an example.

      Comment by IgnorantGuru | March 5, 2012 | Reply

  2. Yes, sorry for the noise – I realized it after posting.

    Comment by ColdFeetBob | March 5, 2012 | Reply

    • No problem – thanks for your feedback.

      Comment by IgnorantGuru | March 5, 2012 | Reply

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: