Skip to content

Instantly share code, notes, and snippets.

@spences10
Created March 9, 2023 13:17
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 spences10/7bee4d963deb4b842201c60e32da3bdf to your computer and use it in GitHub Desktop.
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.
#!/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