Skip to content

Instantly share code, notes, and snippets.

@nitatemic
Created December 7, 2023 18:34
Show Gist options
  • Save nitatemic/d1912c205a14e8cf33d8a834fc6fe4b4 to your computer and use it in GitHub Desktop.
Save nitatemic/d1912c205a14e8cf33d8a834fc6fe4b4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if the argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <folder_path>"
exit 1
fi
# Store the folder path provided as an argument
folder_path=$1
# Check if the folder exists
if [ ! -d "$folder_path" ]; then
echo "Folder not found: $folder_path"
exit 1
fi
# Move files from subfolders to the topmost folder
find "$folder_path" -mindepth 2 -type f -exec bash -c 'mv "$1" "${1%/*}/../.." ' _ {} \;
# Remove empty directories
find "$folder_path" -type d -empty -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment