Skip to content

Instantly share code, notes, and snippets.

@jorgemanrubia
Created January 15, 2023 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgemanrubia/3f6c0706a8fb22f3f66d53ac2dbca3ae to your computer and use it in GitHub Desktop.
Save jorgemanrubia/3f6c0706a8fb22f3f66d53ac2dbca3ae to your computer and use it in GitHub Desktop.
ChatGPT prompt 3
#!/bin/bash
# Set the directory path where the folders are located
dir_path="/path/to/directory"
# Get a list of all the folders in the directory
folders=($(ls -t $dir_path))
# Delete all folders except the most recent 10
for ((i=10; i<${#folders[@]}; i++)); do
rm -r "$dir_path/${folders[i]}"
done
bash script to delete all the folders in a directory but the most recent 10 ones in MacOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment