LinuxQuestions.org
Visit Jeremy's Blog.
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 12-16-2003, 06:03 AM   #1
Jalalabee
Member
 
Registered: Aug 2003
Distribution: Slackware 10.2
Posts: 102

Rep: Reputation: 15
rename scripting / locations on partitions


Hello to any readers of my problem-os.

Alright, I was intrested in creating a script specific to renaming. Not asking for a script, just asking where I could go for more specific information on creating a renaming bash script.

What I want to do with the script:

Rename all files in all folders from a folder, ie: /home/stuff/music/*/*
Renaming them in this content: all letters to lowercase and all spaces to _.

That is all for that ... also ... I've heard that different partition hold different large specific folders. What I want to do is keep my music and some of my things, format and upgrade. (I'm not good enough to delete all the useless folders / files and upgrade)

Anyway!

Thanks for reading and THANKS very much for any help. :-D
 
Old 12-16-2003, 06:41 AM   #2
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 30
Hi,

The Advanced Bash Scripting Guide is good:

http://www.tldp.org/LDP/abs/html/

For the letters-to-lowercase and spaces-to-underscore conversions I would use tr, but sed and awk will do (maybe better?) too.

As for your other question: it depends on how you have partitioned your harddrive. If you for instance have a /home partition, then you can put your stuff there, and make sure not to format that when you format and upgrade. Or maybe you have some FAT32 partition somewhere, then you can put it there, or if you have two harddrives, or... Well, if you give us info on your partitioning we can help you better
 
Old 12-16-2003, 06:52 AM   #3
spuzzzzzzz
Member
 
Registered: Sep 2003
Location: Australia
Distribution: Gentoo
Posts: 465

Rep: Reputation: 30
i'm not an expert on shel scripting by any means, but here are a few facts that might help:
1) You will find the 'for' statement very useful - it looks something like this:
for FILENAME in *.mp3; do
echo $FILENAME
done
(obviously instead of "echo $FILENAME" you would want to do something useful)

2) The ASCII character representation will be important. In hexadecimal notation, the lowercase letters go from 0x61 to 0x79 while the uppercase characters go from 0x41 to 0x59 (ie 'a' is 0x61 while 'A' is 0x41). The binary representation of hex 6 is 0110 while the binary representation of hex 4 is 0100. Hex 5 = binary 0101 while hex 7 = binary 0111. In other words, to change an uppercase letter into a lowercase letter, you just have to force bit 5 to 1. You could do this with a bitwise or:
letter = letter | 0x32; //in C++ notation (I don't know how to do this in a shell script) 0x32=00100000

its not a complete answer, but i hope it helps. You could always try googling for "linux shell scripting" or you could look for ebooks on P2P or real books on Amazon.com
 
Old 12-16-2003, 07:19 AM   #4
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 30
Or, when you're scripting, skip the bitwise or and do tr '[A-Z]' '[a-z]'
 
Old 12-16-2003, 08:41 AM   #5
zib
LQ Newbie
 
Registered: Dec 2003
Distribution: MDK8.2
Posts: 14

Rep: Reputation: 0
Uhm, since I'm a lazy git today, here's a lazy git solution, but, nevertheless, it works.

create a file called, for example, renamemp3s.sh in /usr/local/bin
add the code below to it.
save and chmod the file 755.
goto the directory where your files are that you want to rename
execute the script
done

here's the code:

Code:
for name in *
do
        na=`echo "$name"|tr ' ' '_'`
        if [ "$na" != "$name" ]
        then
                echo mv "$name" "$na"
                mv "$name" "$na"
        fi
done

perl -we 'for (<*>) { $f = $_; s~(.*)~\L$1~; rename $f, $_ }'
There's of course plenty of extra options to throw in, such as recursive dir search, special chars convo, but this is what you asked for.

Have fun
/j.
 
Old 12-18-2003, 01:11 PM   #6
Jalalabee
Member
 
Registered: Aug 2003
Distribution: Slackware 10.2
Posts: 102

Original Poster
Rep: Reputation: 15
could i simply change it to do all files in dir by..

rename /*/$f instead of rename $f ? ill try it out, im just working on logic, im still mudding my way through that bash scripting how-to
 
  


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
Application locations? nthnmsnr Linux - Newbie 4 07-22-2005 09:38 AM
Rename Partitions on RH9? Saxton Linux - General 4 06-27-2005 11:25 AM
Locations for new programs. unreal128 Linux - Newbie 1 05-20-2005 05:03 PM
App locations Where do they go?? mcgrath0087 Linux - Newbie 2 02-14-2004 10:10 PM
File Locations stodgel Linux - General 1 06-13-2003 09:02 AM


All times are GMT -5. The time now is 08:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration