To copy files from one folder to another in Linux while avoiding overwriting existing files with the same name (ignoring the extension), you can use the following approach:
First, create a list of files in the source folder (excluding extensions):
cd /source/
find . -type f -exec sh -c 'basename "$1" | cut -d "." -f 1' _ {} \; > /tmp/source_files.txt
Next, create a similar list of files in the destination folder:
cd /destination/
find . -type f -exec sh -c 'basename "$1" | cut -d "." -f 1' _ {} \; > /tmp/destination_files.txt
Now compare the two lists and copy only the files that don’t exist in the destination folder:
while read -r filename; do
if ! grep -q "^$filename$" /tmp/destination_files.txt; then
cp "/source/$filename"* /destination/
fi
done < /tmp/source_files.txt
This script ensures that files are copied only if their base names (ignoring extensions) don’t already exist in the destination folder. Adjust the paths (/source/ and /destination/) as needed for your specific case. Happy copying!