LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 11-08-2006, 09:19 AM   #1
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Distribution: Frustrated Ubuntu 6.10 Edgy User
Posts: 257

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:

Quote:
#!/bin/bash

for i in *.pdf
do
j=`echo $i | sed 's/.pdf/_.pdf/'`
mv $i $j
done
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.


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

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

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


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
bash script? how to rename files in random way? lefty.crupps Linux - Software 15 06-08-2014 03:47 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


All times are GMT -5. The time now is 10:06 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration