Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Last active July 3, 2022 02:29
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 luckylittle/2395ac9066cfb6754d961914e8d5ea98 to your computer and use it in GitHub Desktop.
Save luckylittle/2395ac9066cfb6754d961914e8d5ea98 to your computer and use it in GitHub Desktop.
Creates folders based on filenames (without extensions) in the current directory
#!/bin/bash
ls -1 *.mkv | rev | cut -d '.' -f2- | rev | xargs mkdir -v
for i in $(ls -1 *.mkv); do mv -v ${i} ${i%.mkv}; done
# Before:
# [lmaly@localhost The_Man_in_the_High_Castle]$ ls -1 *.mkv
# The.Man.in.the.High.Castle.S01E01.720p.WEBRip.x264-BATV.mkv
# The.Man.In.The.High.Castle.S01E02.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E03.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E04.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E05.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E06.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E07.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E08.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E09.720p.WEBRip.x264-SERIOUSLY.mkv
# The.Man.In.The.High.Castle.S01E10.720p.WEBRip.x264-SERIOUSLY.mkv
# After:
# [lmaly@localhost The_Man_in_the_High_Castle]$ ls -1 -d */
# The.Man.in.the.High.Castle.S01E01.720p.WEBRip.x264-BATV/
# The.Man.In.The.High.Castle.S01E02.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E03.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E04.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E05.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E06.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E07.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E08.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E09.720p.WEBRip.x264-SERIOUSLY/
# The.Man.In.The.High.Castle.S01E10.720p.WEBRip.x264-SERIOUSLY/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment