#!/bin/bash # Define the pattern for the files you want to move file_pattern="201[5,9]*" # Find all directories containing the files directories=$(find . -mindepth 1 -maxdepth 1 -type d) # Loop through each directory for dir in $directories; do # Check if the RHEL7 subdirectory exists if [ -d "$dir/RHEL7" ]; then # Move the files matching the pattern into the RHEL7 subdirectory mv "$dir"/$file_pattern* "$dir/RHEL7/" 2>/dev/null echo "Moved files in $dir to $dir/RHEL7/" else echo "RHEL7 subdirectory not found in $dir" fi done