Dynamically append text to filenames in Bash



As an IT administrator, it is important to be able to modify files on the server with ease. It is often necessary to append text to existing filenames, for example to indicate the revision of a document or the type of file. This can be done in a few simple steps using the Bash command line interface.

The first step is to create a variable containing the text that will be appended to the filename. This can be done with the following command:

TEXT=\_v1\

Next, the list of filenames that need to be modified should be stored in a variable. This can be done with the following command:

FILENAMES=(file1.txt file2.txt file3.txt)

Now, a loop can be used to iterate through the list of filenames and append the text to each of them. This can be done with the following command:

for filename in \${FILENAMES[@]}\ ; do mv \$filename\ \$filename$TEXT\ ; done

This will iterate through the list of filenames and append the text stored in the TEXT variable to each of them.

Finally, the modified list of filenames can be printed out to confirm that the changes have been made. This can be done with the following command:

echo \${FILENAMES[@]}\

If the changes were successful, this will output the modified list of filenames with the appended text.

In this way, IT administrators can easily append text to existing filenames using the Bash command line interface. This can be a useful tool for quickly modifying files on the server and keeping track of different versions of documents or types of files.

Inquire Now

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Find your next full or part-time role here

ScaleDesk can either help you find your next full time gig or a part time side gig where you can create extra income!

Onboard with us once
Skip HR screening and go to the final interview with with only your resume and a video interview you never have to redo
Get paid electronically every month for the hours you work
We will be your reference even if you work for us once

IT Teams: Use ScaleDesk to augment your team

Schedule Demo