If you have a use case where you want to prefix files within a directory with number sequences such as 001, 002, 003 .... 999. Well, for such a case you can simply write a bash script that can do this job quickly.
Below is a very simple script in bash that will do this job for you, just keep the file in the folder where you want to run it. For safety, it will ask you to enter the list of file extensions that you want to rename with a number prefix, you can add any number of file extensions separated by space. example "csv xml xls xlsx json txt"
#!/bin/bash
# Script to add a numeric prefix to files within a directory
#
# Author: Code2care.org
# Date Created: 4/5/2023
#
# Note: User needs to provide the file extensions eg. txt, CSV, xlsx
# to consider only those types.
#
# DISCLAIMER: Use this script at your own risk.
# We are not responsible for any damage it may cause.
#
echo "Enter the file extensions you want to rename (separated by spaces):"
read -ra extensions
file_count=1
for ext in "${extensions[@]}"; do
for file in *."$ext"; do
extension="${file##*.}"
new_name="$(printf "%03d" $file_count)-$file"
mv "$file" "$new_name"
((file_count++))
done
done
Example:
# ./prefix-file-script.sh
Enter the file extensions you want to rename (separated by spaces):
csv txt
# ls -l
total 8
-rw-r--r-- 1 c2ctech staff 0 May 4 23:09 001-file-c.csv
-rw-r--r-- 1 c2ctech staff 0 May 4 23:09 002-file-d.csv
-rw-r--r-- 1 c2ctech staff 0 May 4 23:09 003-file-a.txt
-rw-r--r-- 1 c2ctech staff 0 May 4 23:09 004-file-b.txt
-rwxr-xr-x@ 1 c2ctech staff 669 May 4 23:02 prefix-file-script.sh

You may customize the script if you have files over 999 and if you want to have a custom string prefixed as well or use the underscore operator instead of a hyphen.
Have Questions? Post them here!
- How to Assign Bash Command to Variable
- How to Kill a port using bash terminal command?
- Bash For Loop Example
- bash: netstat: command not found
- Bash getopts Command Example
- How to fix bash ping command not found error
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- [fix] bash: ssh: command not found
- Fix bash: script.sh: Permission denied Error
- bash: ls command to see list files in current directory all subdirectories
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- How to use Autocomplete and Autosuggestion in Shell Commands
- Bash Hello World! Script Tutorial
- Install Bash Completion on macOS
- bash get year 2021 calendar
- How to create new user account in Windows bash
- Bash command to wait for seconds
- Know Bash shell version command
- How to start or open a new bourne-again shell (bash) session on Windows using Command Line CMD
- How to check your IP using bash for Windows?
- Bash Script to prefix files with sequential numbers in a directory
- How to Compare Strings in Bash
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- How to know the current shell you are logged in?
- List all Username and User ID using Bash Command
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error - Java
- How to install Microsoft Outlook App on Mac - MacOS
- Mac Auto Move Mouse Pointer Every X Seconds to Keep Screen Awake - MacOS
- All directional arrows codes for HTML - Html
- How to add sleep in Powershell Script - Powershell
- How to redirect SharePoint Site Collection to different URL - SharePoint
- What does apt-get update command does? - Linux
- Install Native M1/M2 Apple Silicon based IntelliJ IDEA IDE on Mac - MacOS