Bash script to remove capitalisation and spaces form a filename
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Bash script to remove capitalisation and spaces form a filename
I need some help removing capitalisation and spaces from a filename. This is what I have so far, but you'll see the errors it's generating:
Code:
[scuzzy@slackdell /home/scuzzy/test]$ cat /usr/bin/upper2lower
#!/bin/bash
# upper2lower - convert all files in a directory from upper
# to lower case filenames and replace spaces with _
for f in *; do # turn all spaces into underscores
mv \"$f\" `echo \"$f\" | tr [:space:] _`
done
for g in *; do # make all characters lowercase
mv $g `echo $g | tr A-Z a-z`
done
# EOF
[scuzzy@slackdell /home/scuzzy/test]$ ls
file\ with\ SPACES\ and\ CAPS
file\ with\ spaces_in_name
[scuzzy@slackdell /home/scuzzy/test]$ upper2lower
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
[scuzzy@slackdell /home/scuzzy/test]$
Re: Bash script to remove capitalisation and spaces form a filename
Quote:
Originally posted by scuzzman
[code] [scuzzy@slackdell /home/scuzzy/test]$ upper2lower
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.