Skip to content

Instantly share code, notes, and snippets.

@androiddevnotes
Created February 17, 2022 00:10
Show Gist options
  • Save androiddevnotes/578afd7319edfe34fa06e22a51ac45f7 to your computer and use it in GitHub Desktop.
Save androiddevnotes/578afd7319edfe34fa06e22a51ac45f7 to your computer and use it in GitHub Desktop.
Bash script to make directory from file name and move the file inside the directory. Run: bash script.sh
#!/bin/bash
for file in $(find . -name "*.md" -type f)
do
echo "file: $file"
filenamewithextension=${file##*/}
echo "file name with extension: $filenamewithextension"
mkdir ${filenamewithextension%.*}
echo "file name without extension: ${filenamewithextension%.*}"
mv ${filenamewithextension} ${filenamewithextension%.*}/${filenamewithextension}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment