Hi,
I just need to know a simple command to bulk renaming.
I have hundreds of .DEB files. I want to remove 4%3a from all file names.

example :
old name :
ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb
new name :
ark-kde4_4.0.3-0ubuntu4_i386.deb

I know there is a "rename" command but I don't know it's use.

Thank you

Dani AI

Generated

Short, practical add‑on: the loop posted works, and ’s script is a nice ready tool. For a quick, safer substitution on Ubuntu you can use the Perl-based rename utility to preview changes and then apply them.

Try a dry run first (shows what would change, no files touched):

rename -n 's/4%3a//' *.deb

If the output looks correct, run the same command without -n to perform the rename:

rename 's/4%3a//' *.deb

If the filenames are URL-encoded ( %3a == : ) and you want to restore the colon rather than drop the epoch, do:

rename -n 's/4%3a/4:/' *.deb

Notes and cautions:

  • On some systems there are two different rename utilities; the examples above use the Perl/prename style (the one that accepts s///). If rename on your box uses a different syntax, check man rename before running commands.
  • If files live in subdirectories or have spaces, run a safe find+xargs pipeline with null separators (preview first):
find . -type f -name '*4%3a*' -print0 | xargs -0 rename -n 's/4%3a//'
  • Watch for collisions: removing the same substring from different names can produce identical target names. Always do the dry run, check for duplicates, and back up important files before mass changes.

Summary checklist: run a dry run, confirm results, consider replacing %3a with : if these are Debian package epochs, then perform the actual rename. This keeps the simple approach from and the convenience of ’s script while adding a quick, safe workflow.

Recommended Answers

All 7 Replies

Usually we use the "mv" (move) command to rename a file. Try something like this!

#!/bin/sh

for FILE in $(find . -type f -name '*4%3a*'); do
  NEWNAME=$(echo $FILE|sed s/'4%3a'//)
  mv -v $FILE $NEWNAME
done

If the files are all in one directory, you can run this from in that directory and it should get all of them. It's very basic, so if you run into any problems let us know. It worked on a test run with files formatted like your example.

Hope this helps!
-G

Forgot to add comments!

#!/bin/sh

# first we need a list to work from.  the
# "for" statement will loop through the results
# of our "find" command, using each result in turn
# as "$FILE".  The find command that I used will
# recursive look in subdirectories as well.  You can
# fix that with a flag, or you could use something
# like `ls |grep '4%3a'`
for FILE in $(find . -type f -name '*4%3a*'); do

  # here we use sed to get rid of the unwanted string
  # and store it as "$NEWNAME"
  NEWNAME=$(echo $FILE|sed s/'4%3a'//)

  # here we do the actual work!
  mv -v $FILE $NEWNAME

done

How to use this ? Sorry I don't know.
Because it's not a single line command.

Hmm... well, technically you could run it all on one line like this: for FILE in $(find . -type f -name '*4%3a*'); do NEWNAME=$(echo $FILE|sed s/'4%3a'//); mv -v $FILE $NEWNAME; done but that's kind of ugly :-P

What we have here is called a shell script. What you'll probably want to do is paste the script from above into a text file. Name that text file "" or something easy to remember. Copy it into your ~/bin directory, or if this is a temporary project, save it in the directory where all those files live, and execute it like: $ sh /path/to/myrename.sh I hope that's not too confusing.
-G

commented: Perfect sollution +2

Thank you..
It works as you say.. It's perfectly working

Thanks again

Hi,
I just need to know a simple command to bulk renaming.
I have hundreds of .DEB files. I want to remove 4%3a from all file names.

example :
old name :
ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb
new name :
ark-kde4_4.0.3-0ubuntu4_i386.deb

I know there is a "rename" command but I don't know it's use.

Thank you

you can use the script here
eg usage

# ./script.sh -s "4%3a" -e "" -d "*.deb" # display all files to be renamed
# ./script.sh -s "4%3a" -e "" -d "*.deb"  #remove -d to do actual rename

Thank you ghostdog74,
This one is also userfull

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.