Skip to main content

Raymii.org Raymii.org Logo

Quis custodiet ipsos custodes?
Home | About | All pages | Cluster Status | RSS Feed | Gopher

Bash script for massive rename to numbers

Published: 14-09-2008 | Author: Remy van Elst | Text only version of this article


❗ This post is over thirteen years old. It may no longer be up to date. Opinions may have changed.

Table of Contents


And here is another nice little script for a problem I have. I use awesome as window manager, and in my rc.lua file i've setup some nice tweaks so that my wallpaper changes every 5 minutes to a new one randomly chosen from /usr/share/wallpapers/.

I'm developing a desktop monitoring app, Leaf Node Monitoring, open source, but paid. For Windows, Linux & Android, go check it out.

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.

(done by: awsetbg -r '/usr/share/wallpapers' in a crontab.)

I have a lot of wallpapers, over 1500. awsetbg/feh has some problems with filenames and so once in a while I got an error message from feh,

This scripts renames all the jpg files in a folder to a number. Instead of having Beach.jpg, Clouds.jpg and Tux.jpg you will have 1.jpg, 2.jpg and 3.jpg.

Script:

#!/bin/bash
RAYMIIWALL=1

#convert everything to lowercase - you need the rename command.
rename 'y/A-Z/a-z/' *

for i in {*.jpg,*.jpeg}; 
    do mv -f -v "$i" "$RAYMIIWALL.jpg";
    let "RAYMIIWALL += 1"
done
exit 0

If you get an error like:

mv: cannot stat '*.jpeg': No such file or directory then it means that there are no jpeg files to rename.

Tags: bash , rename , snippets