LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   recursive rename of folders (https://www.linuxquestions.org/questions/linux-newbie-8/recursive-rename-of-folders-4175411504/)

BreezyBadger 06-14-2012 05:24 PM

recursive rename of folders
 
After using shred on a directory tree I am left with a structure of empty folders and subfolders. I'd like to rename the directories to something meaningless before deleting them, by replacing every character of the original name with a string (for instance 'app'). I've tried a few scripts found online but did not succeed in achieving the hoped-for result. I want to know what command or bash script to use in order to do that. Thanks.

Kustom42 06-14-2012 05:26 PM

You could do a find with an xargs but if you give some more detailed info with examples of what you are trying to do we can give you more specific examples of the code to write.

BreezyBadger 06-14-2012 06:02 PM

Quote:

Originally Posted by Kustom42 (Post 4703503)
You could do a find with an xargs but if you give some more detailed info with examples of what you are trying to do we can give you more specific examples of the code to write.

For example, if I have a structure of folders like dir1>dir2>dir3, I would like to rename it to look like this: appappappapp>appappappapp>appappappapp

I have tried some commands like:
Code:

find . -depth -name "*[a-zA-Z0-9]*" -exec bash -c 'dir=${1%/*} base=${1##*/}; mv "$1" "$dir/${base//app/ }"' _ {} \;
Code:

find /path/to/folder -print0 | xargs -0 mv [a-zA-Z0-9] app
and also the script from http://slash4.de/tutorials/Linux_ren...ders_recursive, but did not get the desired result. Perhaps my syntax is wrong.

chrism01 06-14-2012 06:08 PM

It looks like you are trying to do the equivalent of shredding the dirs themselves....
Given that dir entries in *nix ARE files, why not just use shred; much simpler?


All times are GMT -5. The time now is 04:07 AM.