Shell Script To Rename File Name To Lowercase
Posted in File-management
This script use tr command to convert uppercase file name to a lowercase file name. The tr utility copies the given input to produced the output with substitution or deletion of selected characters. tr abbreviated as translate or transliterate. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set i.e. it is used to translate characters.
#!/bin/bash # Write a shell script that changes the name of the file passed as argument # to lowercase. # ------------------------------------------------------------------------- # Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- file="$1" if [ $# -eq 0 ] then echo "$(basename $0) file" exit 1 fi if [ ! $file ] then echo "$file not a file" exit 2 fi lowercase=$(echo $file | tr '[A-Z]' '[a-z]']) if [ -f $lowercase ] then echo "Error - File already exists!" exit 3 fi # change file name /bin/mv $file $lowercase
Download - Email this to a friend - Printable version
Is your site working? Monitor Your Web Site 24/7. Get SMS alerts on server downtime! Free 30-day trial including 20 SMS!
Related Other Helpful Shell Scripts:
- Shell script to rename given file names to from uppercase to lowercase OR lowercase to uppercase
- Shell Script To Translate All Characters In a File To Lowercase
- Shell Script To Count English Language Articles Such As 'A', 'An' and 'The'
- Shell Script To Delete All Even Numbered Line From a Text File
- Shell Script To Delete Files In The First Directory Which Are Similarly Named In The Second Directory
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: echo command, eq, exit 1, fi, file names, filesystem, if command, mv command, rename files, tr command ~ Last updated on: September 16, 2008

