In this project, I had to write a Bash script that would create 25 empty files with sequential numbering. The script needed to be designed to create the next batch of 25 files each time it ran, starting with the last or maximum number that already existed in the directory.
I started by defining the base filename using my name "Alex" that would be used for all files.
Next, I needed to determine what the highest existing number was in the current directory so I could start numbering from there. This required using multiple commands chained together.
The command chain first lists all files starting with "Alex" followed by numbers, then extracts just the numbers, sorts them numerically, and takes the highest value.
I implemented a for loop to create 25 sequential files using the touch command.
To verify the script worked properly, I added a command to display all files in the directory:
Here's my complete Bash script that fulfills all the requirements:
The 2>/dev/null part of the command redirects any error messages to /dev/null, which prevents errors from appearing if no matching files exist yet.