#!/bin/bash # This script can copy or move files from one folder to another, # removing special characters in file names that can cause file system # inconsistencies # HOW TO USE: # 1. Open a terminal and navigate to the directory containing the script file. # 2. Make the script executable by running the following command: # -> chmod +x bkpfiles.sh # 3. Run the script with the source directory and destination directory as arguments: # -> ./bkpfiles.sh /path/to/source/directory /path/to/destination/directory src_dir=$1 dest_dir=$2 # Create destination directory if it doesn't exist mkdir -p "$dest_dir" # Iterate over each file in the source directory for file in "$src_dir"/*; do # Remove special characters from the filename filename=$(basename "$file" | tr -cd '[:alnum:] ._-') # Copy the file to the destination directory with the sanitized filename cp "$file" "$dest_dir/$filename" # Or you can move all files to the destination directory with this command: # mv "$file" "$dest_dir/$filename" done