Useful Terminal Trick - Putting a Bunch of Files in Eponymous Folders
I just donwloaded the caption files to a bunch of video clips, and wanted each one to go in a folder with its same name (minus the file extension), cos that’s where the work on each clip is going to happen. I found a script to do that all at once from the Terminal. From here:
> for file in *.srt; do
> dir=${file%%.*}
> mkdir -p -- "$dir"
> mv "$file" "$dir"
> done
Note the semicolon that appears after the file extension, but before the do
1. It’s nice to be able to do this at the command line, without having to write a script, as a one-off thing.
-
I put the semicolon after
do
at first, and had to figure out why the following command was invalid… 😜 ↩