79171013

Date: 2024-11-08 17:31:59
Score: 0.5
Natty:
Report link

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

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Alen Schmitt