LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 05: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, 05:26 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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, 06: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, 06:08 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 01:10 PM
Shell script, recursive rename/string replace? lrall Linux - General 1 07-27-2010 10:12 PM
recursive rename zomane Programming 8 06-26-2010 11:08 AM
bash script to create folders including making recursive folders.... linux-bandit Linux - Software 8 11-28-2009 01:50 AM
Sync files not folders with rsync (non recursive) ehlers Linux - Software 7 03-11-2009 09:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:25 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
Open Source Consulting | Domain Registration