Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Created June 10, 2017 23:19
Show Gist options
  • Save jcanfield/cda8ab8027ec32e5273af0d685add5d8 to your computer and use it in GitHub Desktop.
Save jcanfield/cda8ab8027ec32e5273af0d685add5d8 to your computer and use it in GitHub Desktop.
Use bash and linux tools to rename files in a folder, to the folder name.
#!/bin/bash
# SYNOPSIS: Rename all files in folder to match folder name.
# Testing 1
# rename -vn 's:(/[^/]*)/[^/]*$:$1$1.mkv:' folder/*/*.mkv
# Testing 2
#for f in folder/*/*.mkv;do dn="${f%/*}";echo mv -v "$f" "${dn}/${dn##*/}.mkv";done
# Testing #3
# find folder/* -maxdepth 0 -type d -execdir sh -c 'test -f "$0"/*.mkv"&&echo mv -v "$0"/*.mkv "$0/${0##*/}.iso"' '{}' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment