Created
October 29, 2020 10:38
-
-
Save luckylittle/1103204fada13db167b2d88bcc55bd4c to your computer and use it in GitHub Desktop.
Safely rename files inside directories with the same name as the parent directory name
This file contains hidden or 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
| #!/bin/bash | |
| # Thu Oct 29 10:34:58 UTC 2020 | |
| # Lucian Maly, lmaly@redhat.com | |
| for pathname in $(ls -d1 */); | |
| do | |
| cd "${pathname}" || exit | |
| for file in * | |
| do | |
| mv -iv "${file}" "$(basename "${pathname}").${file##*.}" | |
| done | |
| cd .. | |
| done | |
| # Before: | |
| # Active_Directory_Administration_Cookbook/9781789806984-ACTIVE_DIRECTORY_ADMINISTRATION_COOKBOOK.pdf | |
| # Active_Directory_Administration_Cookbook/9781789806984_Code.zip | |
| # Active_Directory_Administration_Cookbook/9781789806984.epub | |
| # Active_Directory_Administration_Cookbook/9781789806984.mobi | |
| # After: | |
| # Active_Directory_Administration_Cookbook/Active_Directory_Administration_Cookbook.pdf | |
| # Active_Directory_Administration_Cookbook/Active_Directory_Administration_Cookbook.zip | |
| # Active_Directory_Administration_Cookbook/Active_Directory_Administration_Cookbook.epub | |
| # Active_Directory_Administration_Cookbook/Active_Directory_Administration_Cookbook.mobi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment