Here's a straightforward bash script to flatten just one level of directories while keeping deeper subfolders intact.
You can save as flatten-one-level.sh
#!/bin/bash
for dir in */; do
if [ -d "$dir" ]; then
echo "Processing directory: $dir"
for file in "$dir"*; do
if [ -f "$file" ]; then
mv "$file" .
fi
done
rmdir "$dir" 2>/dev/null || true
fi
done
To make the script executable and run it:
chmod +x flatten-one-level.sh
Hope it will be helpful. Thanks