LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-04-2004, 06:52 AM   #1
Goya
LQ Newbie
 
Registered: Aug 2004
Posts: 1

Rep: Reputation: 0
Bash script


Hello,
I need help with bash script. This script must browse directory tree and every file include directories rename from UPPER to lower case.


#! /bin/sh
find $1 -print | while read x ;
do
mv $x $(echo $x | tr 'A-Z' 'a-z')
done


I use this script, but it rename files and directories only in actual directory.

Thank You.
 
Old 08-04-2004, 10:43 AM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
Quote:
find

find - search a folder hierarchy for files that meet a desired criteria

SYNTAX
find [path...] [expression]

DESCRIPTION
find searches the directory tree rooted at each given file name
by evaluating the given expression from left to right,
according to the rules of precedence (see section OPERA_
TORS), until the outcome is known (the left hand side is
false for and operations, true for or), at which point
find moves on to the next file name.

The first argument that begins with
- ( ) , or !
is taken to be the beginning of the expression; any
arguments before it are paths to search, and any arguments
after it are the rest of the expression. If no paths are
given, the current directory is used. If no expression is
given, the expression `-print' is used.


find exits with status 0 if all files are processed suc_
cessfully, greater than 0 if errors occur.
you did not specify a particular $PATH to use as explained in RED........so it only stays in the current directory
 
Old 08-04-2004, 11:56 AM   #3
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
Re: Bash script

Quote:
Originally posted by Goya
I use this script, but it rename files and directories only in actual directory.
What are you supplying as an argument to the script? Which are you doing:
./scriptname
./scriptname /path/to/directory

If you're doing the first one then $1 in your script is null.
 
Old 08-04-2004, 12:04 PM   #4
wipe
Member
 
Registered: Jun 2004
Location: High Green
Distribution: Fedora Core 4
Posts: 180

Rep: Reputation: 30
This thread is somewhat similar:
http://www.linuxquestions.org/questions/history/212607

You could use this:
Code:
#!/bin/bash
IFS=$'\n'
find $* -depth | while read x; do
        base=`basename "$x"`
        new=`echo $base | tr A-Z a-z`
        [ "$new" != "$base" ] && mv "$x" "$(dirname "$x")/$new"
done
If you don't give it arguments, it uses the current directory. Have fun!

Simon

Last edited by wipe; 08-04-2004 at 12:05 PM.
 
  


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
Bash script Linh Programming 4 04-21-2004 05:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script brian0918 Programming 7 06-12-2003 06:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:20 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