LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-05-2004, 08:50 PM   #1
andy753421
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 65

Rep: Reputation: 15
chaging directory names to lower case


back when i only used windows i made all my directorys nice and pretty with uppercase letters and spaces, now when im using linux its getting to be a pain trying to remember whether i made something start with a P or a p, so is there a way to have it go through a folder and recursively change all folder names to all lowercase letters? also can i do something simmilar changeing spaces to underscores?
 
Old 05-06-2004, 10:51 PM   #2
meonkeys
Member
 
Registered: Apr 2004
Location: Minneapolis
Distribution: Ubuntu
Posts: 45

Rep: Reputation: 15
eliminate spaces and lowercase filenames

Here's a script I use to eliminate spaces (save it as 'eliminate_spaces'):
Code:
#!/bin/bash
# $Id: eliminate_spaces,v 1.5 2004/05/07 03:42:28 adamm Exp $

# eliminates spaces in given filenames by turning one or more spaces
# into a single underscore

if [ $# -eq 0 ]
then
  echo "Usage: `basename $0` <FILE...>"
  exit 65
fi
  
for arg
do
  oldname="$arg"
  newname=`echo "$oldname" | sed -e 's/ \+/_/g'`
  [ "$oldname" != "$newname" ] && mv -i "$oldname" "$newname"
done
Simiarly, here's one to lowercase files or directories (save it as 'lowercase_filename'):
Code:
#!/bin/bash
# $Id: lowercase_filename,v 1.1 2004/05/07 03:46:15 adamm Exp $

# makes all characters in a filename lowercase

if [ $# -eq 0 ]
then
  echo "Usage: `basename $0` <FILE...>"
  exit 65
fi

for arg
do
  oldname="$arg"
  newname=`echo "$oldname" | tr 'A-Z' 'a-z'`
  [ "$oldname" != "$newname" ] && mv -i "$oldname" "$newname"
done
Say you want to find a bunch of files and feed them to the proper script. Try something like this:
Code:
$ find . | grep '[[:space:]]' | xargs eliminate_spaces
$ find . | grep '[[:upper:]]' | xargs lowercase_filename
 
Old 05-11-2004, 02:12 PM   #3
andy753421
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 65

Original Poster
Rep: Reputation: 15
that seems to work pretty good except the one that changes spaces to underscores doesnt work recursavely because it finds a folder called "folder one" and then trys to change just "folder" and it doesnt work
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Upper and lower case problem when mount hardisk UltraSoul Linux - Newbie 1 10-28-2005 08:50 AM
Renaming All Caps Filename Into Lower Case slpwkr Linux - General 3 06-03-2005 06:23 AM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM
Lower case to upper case letter sudhasmyle Programming 1 12-03-2004 04:15 AM
Apache and upper or lower case. dsiguy Linux - General 3 02-04-2003 11:02 AM


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