Created
March 9, 2023 13:17
-
-
Save spences10/7bee4d963deb4b842201c60e32da3bdf to your computer and use it in GitHub Desktop.
A bash script to move files from a nested folder structure like `posts/2023/02/25/passing-sveltekit-page-server-js-data-to-page-js/index.md` and rename the `.md` file with the name of the parent folder and move it to a new folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# create new folder called new | |
mkdir new | |
# find all index.md files in the folder structure | |
# and loop through them | |
find . -name 'index.md' | while read file; do | |
# get the parent folder of the index.md file | |
parent=$(dirname "$file") | |
# get the name of the parent folder | |
name=$(basename "$parent") | |
# move the index.md file to the new folder with the new name | |
mv "$file" "new/$name.md" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment