Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:44:23+00:00 2026-05-26T23:44:23+00:00

I have this script that I’m running to rename all the files in a

  • 0

I have this script that I’m running to rename all the files in a folder to “1.png”, “2.png”, etc, but sometimes it will completely erase (or move the file somewhere else, I have no idea what’s happening) the first 10 or so images. This seems to happen whenever there’s more than 10 images inside the folder. The script I’m running is below, anyone have any ideas?

#!/bin/bash
cd "$1"
cnt=1
for fname in *
do
if [ "$1" != '/var/www/cydia.stumpyinc.com/theme/images/browse/icons/' ]
then
    mv "$fname" ${cnt}.png
    cnt=$(( $cnt + 1 ))
fi
done

EDIT

I’m also getting this error in the terminal, don’t know if it’s important or not though

mv: cannot stat `*': No such file or directory
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:44:24+00:00Added an answer on May 26, 2026 at 11:44 pm

    Your script is bizarre: from your description the correct way of renaming everything to a number should be something like:

    #!/bin/bash
    
    
    error() {
        ec=$1
        shift;
        echo "$@" 1>&2
        exit $ec
    }
    
    TARGETDIR="$1"
    
    if [ ! -d $TARGETDIR ] ; then
         error 1 "$TARGETDIR: No such directory"
    fi
    
    if [ "$TARGETDIR" = '/var/www/cydia.stumpyinc.com/theme/images/browse/icons/' ] ; then
         error 1 "Cannot process $TARGETDIR"
    fi
    
    # Okay let's process stuff now...
    
    
    cd $TARGETDIR
    if [ "$(echo *)" = "*" ] ; then
         error 1 "$TARGETDIR: empty directory"
    fi
    
    # calculate zero-padding for the number of files present.
    
    zeros=$(ls -1 | wc -l | wc -c)
    cnt=1
    for k in * ; do 
        if [ -f "$k" ] ; then
              ext=."$(echo $k | awk -F\\. '{ printf $NF }')"
              fn=$(printf "%0${zeros}d" $cnt)
              echo "Converting $k to ${fn}${ext}"
              mv "$k" "${fn}${ext}"
              cnt=$(($cnt+1)) 
        fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script that I am currently running that works great for all
I have this script that displays all the users images which i will display
I have this script in BASH (linux) shells script that adds all *.jar files
know nothing about php, but I have this script that reads a folder and
I have this script that works, but I need to change the format of
I have a Python script that is running a few ls commands. This script
I have this script that will let the user download the data from the
I have this script that only lets users enter a single tag but I
I have this script that basically will show a product or products based on
So I have this script that will rotate images located in a directory, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.