Created
September 21, 2014 12:56
-
-
Save guypursey/a792d42811918518a741 to your computer and use it in GitHub Desktop.
Move files into their own directories, using filenames without extensions.
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
# Credit should go to http://stackoverflow.com/a/12607951/1563507 | |
# Move files into their own directories, using filenames without extensions. | |
die() { echo "$*" >&2; exit 1; } | |
for file in *.md; do # `md` used as example of filtering files one wants to move | |
dir=${file%.md} | |
test -d $dir || mkdir $dir # or just mkdir -p $dir | |
test -f $dir && die "$dir exists and is a file!" | |
mv $file $dir | |
done | |
# Do something with each directory. | |
for dir in *; do ...; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment