Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-08-2006, 09:19 AM   #1
Registered: Sep 2003
Location: Manchester UK
Posts: 264

Rep: Reputation: 30
bash: make rename script traverse directories

Hi, I have written a simple script to rename a load of files from *.pdf to *_.pdf.

The problem I have is that it can't traverse directories, as I have several hundred directories and I don't fancy running the script manually in each one. I have 3 levels of directories that I need it to look in - basically it just needs to do so recursively.

Here is the script:


for i in *.pdf
j=`echo $i | sed 's/.pdf/_.pdf/'`
mv $i $j
It works fine when run from within the folder containing some pdf's, but I can't run it from 1 level up, i.e. encompassing a couple of hundred folders each containing 10's of pdf's.

Any help would be greatly appreciated.

Old 11-08-2006, 10:51 AM   #2
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
find . -name '*.pdf' | while read f
   echo mv $f ${f%.pdf}_.pdf
using echo for safety.
Old 11-08-2006, 10:52 AM   #3
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
try this:
for i in `find . -name '*.pdf'`


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
bash script? how to rename files in random way? lefty.crupps Linux - Software 16 11-03-2015 02:07 PM
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
Bash script to traverse directory tree and rename files intramaweb Programming 3 10-08-2006 12:51 PM
Script to rename directories superior88 Linux - Newbie 4 02-15-2005 10:31 PM
FTP Users are able to Traverse directories up to the root of my server stingay Red Hat 6 10-25-2003 03:22 AM > Forums > Non-*NIX Forums > Programming

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

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