LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-19-2015, 10:27 AM   #1
littlejoe5
Member
 
Registered: Aug 2006
Location: Arizona
Distribution: ubuntu dirivatives mostly Mate
Posts: 260

Rep: Reputation: 19
how to make a script loop


The following script works really well within any one directory.
(I did not write it, and don't remember where I got it, but I have modified it a little. I removed the tr call that converted capitals to lower case.)

~ $ cat bin/nfname.sh
#!/bin/bash
#"nfname" means "normalize Filename", It is intended to remove unacceptable symbols from filenames.
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | sed 's/_-_/_/g'`
done

Now how can I make it loop through all the directories from /home?
 
Old 04-19-2015, 12:04 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,633

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by littlejoe5 View Post
The following script works really well within any one directory.
(I did not write it, and don't remember where I got it, but I have modified it a little. I removed the tr call that converted capitals to lower case.)

~ $ cat bin/nfname.sh
#!/bin/bash
#"nfname" means "normalize Filename", It is intended to remove unacceptable symbols from filenames.
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | sed 's/_-_/_/g'`
done

Now how can I make it loop through all the directories from /home?
Please put your code in CODE tags when posting. Also, please read the "Question Guidelines" link in my posting signature. We will be happy to help, but you will have to provide some effort. You've been here nine years now, and surely have seen many threads like this in that time.

Also, any of the bash scripting tutorials cover this, as well as a brief Google search for "bash script recurse into directories"...like this one, complete with examples:
http://askubuntu.com/questions/53148...ecuting-script
 
1 members found this post helpful.
  


Reply

Tags
loop, scripting


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Bash script issue (for loop inside a loop) Mperonen Programming 3 08-08-2013 02:14 AM
a script to "make" several times in a loop mike1982 Programming 3 02-10-2012 12:54 PM
Make a bash script loop from start evansd321 Linux - Newbie 5 08-29-2008 11:37 AM
Make Loop notsoevil Linux From Scratch 1 02-11-2002 02:51 AM

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

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