Skip to content

Instantly share code, notes, and snippets.

@guypursey
Created September 21, 2014 12:56
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 guypursey/a792d42811918518a741 to your computer and use it in GitHub Desktop.
Save guypursey/a792d42811918518a741 to your computer and use it in GitHub Desktop.
Move files into their own directories, using filenames without extensions.
# 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