Last active
August 29, 2015 14:05
-
-
Save lancelothk/1b46373a33026acce96f to your computer and use it in GitHub Desktop.
Example of shell script – change file extension:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
copy from http://www.ibm.com/developerworks/aix/library/au-unixtext/ | |
Example of shell script – change file extension: | |
$ cat setup_files.ksh | |
mkdir /tmp/mv_demo | |
[ ! -d /tmp/mv_demo ] && exit | |
cd /tmp/mv_demo | |
mkdir tmp JPG 'pictures 1' | |
touch a.JPG b.jpg c.Jpg d.jPg M.jpG P.jpg JPG_file.JPG JPG.file2.jPg file1.JPG.Jpg 'tmp/ | |
pic 2.Jpg' 10.JPG.bak 'pictures 1/photo.JPG' JPG/readme.txt JPG/sos.JPG | |
find . -type f|grep -i "\.jpg$" |sort| tee file_list.txt | |
$ ./setup_files.ksh | |
./JPG.file2.jPg | |
./JPG/sos.JPG | |
./JPG_file.JPG | |
./M.jpG | |
./P.jpg | |
./a.JPG | |
./b.jpg | |
./c.Jpg | |
./d.jPg | |
./file1.JPG.Jpg | |
./pictures 1/photo.JPG | |
./tmp/pic 2.Jpg | |
$ cd /tmp/mv_demo | |
$ cat /tmp/fix_extension.ksh | |
while read f ; do | |
mv "${f}" "${f%.*}.jpg" | |
done < file_list.txt | |
find . -type f|grep -i "\.jpg$" |sort | |
$ /tmp/fix_extension.ksh | |
./JPG.file2.jpg | |
./JPG/sos.jpg | |
./JPG_file.jpg | |
./M.jpg | |
./P.jpg | |
./a.jpg | |
./b.jpg | |
./c.jpg | |
./d.jpg | |
./file1.JPG.jpg | |
./pictures 1/photo.jpg | |
./tmp/pic 2.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment