Skip to main content Logo

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

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

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, 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 $200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!

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



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