LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2012, 06:24 PM   #1
BreezyBadger
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: 0
Question 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.
 
Old 06-14-2012, 06:26 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
Old 06-14-2012, 07:02 PM   #3
BreezyBadger
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Kustom42 View Post
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.
 
Old 06-14-2012, 07:08 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive chown folders & not files gutterboy Linux - Server 2 12-02-2010 02:10 PM
Shell script, recursive rename/string replace? lrall Linux - General 1 07-27-2010 11:12 PM
recursive rename zomane Programming 8 06-26-2010 12:08 PM
bash script to create folders including making recursive folders.... linux-bandit Linux - Software 8 11-28-2009 02:50 AM
Sync files not folders with rsync (non recursive) ehlers Linux - Software 7 03-11-2009 10:53 AM


All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration