Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 890  / 3 Years ago, tue, may 11, 2021, 6:12:57

I have this folder that contains many folders, each containing many files with the name structure .XYZ.zip.



I'd like to rename them (using bash) to XYZ.zip (i.e. un-hide them).



I've seen a question attempting to do a similar thing,



alias deannoy='for annoyingbak in *.bak;do mv "$annoyingbak" ."$annoyingbak";done'>> ~/.bashrc && . .bashrc


but I've not been able to manage to change so it's done recursively for all folders
down from the current folder.


More From » bash

 Answers
6

The for ... in *.bak command searches only the current directory.



You want instead to use the find command, which searches recursively. This command will locate all zip files starting with a dot at any depth in the current directory (.).



find . -iname '.*.zip'


Removing the leading dot is a bit trickier though. The following seems to work (but may have edge cases, caveat emptor).



for f in $(find -iname '.*.zip'); do f2=$(echo $f | sed -re 's/(.*)/.(.*)/1/2/'); echo $f $f2; done


This will print all the operations it would perform (echo $f $f2), if this list looks right change it to mv $f $f2 and it will do the renames.


[#34875] Wednesday, May 12, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bblerest

Total Points: 240
Total Questions: 119
Total Answers: 113

Location: Wallis and Futuna
Member since Mon, May 18, 2020
4 Years ago
bblerest questions
Sun, Apr 16, 23, 13:50, 1 Year ago
Fri, Nov 4, 22, 06:21, 2 Years ago
Tue, Sep 27, 22, 12:22, 2 Years ago
;