Remove dots in filename

Nerd Stuff

I wrote a Bash Script to remove excess periods in a filename. For example, if you had a file named “”, this script will assist in renaming it to “some words in your filename.txt”. Of course, this only works in Linux. You need to save the file below as a .sh and make it executable via the chmod command. Click “Read More” to see the code.

Read more

# Get the filename argument

# Get the extension of the filename

# Remove the extension from the filename

# Replace all dots in the filename with spaces
new_filename="${filename//./ }.$extension"

# Print the suggested new filename
echo "Suggested new filename: $new_filename"

# Prompt the user for confirmation
read -p "Do you want to rename the file? (y/n) " choice

if [[ $choice == "y" || $choice == "Y" ]]; then
    # Rename the file
    mv "$1" "$new_filename"
    echo "File renamed to $new_filename"
    echo "File not renamed"
Read more

Comments are closed.