Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 740
  • Last Modified:

unix command to strip extension from filename

I want to write a script that finds all jpeg files and will convert the extension jpg to JPG and another command that will do the other.
0
dwcronin
Asked:
dwcronin
  • 2
  • 2
1 Solution
 
TintinCommented:
Depending on your Unix flavour and shell, there are quicker/shorter ways of doing this task than the below, but the code below will run on any Unix system.

#!/bin/sh
for file in `find / -name "*.jpg"`
do
  mv $file `echo $file | sed `s/jpg/JPG/'`
done
0
 
ghostdog74Commented:
for only one directory

for file in *.jpg
do    
    mv  $file ${file%%.dpx}.JPG
done
0
 
ghostdog74Commented:
amendment

for only one directory

for file in *.jpg
do    
    mv  $file ${file%%.jpg}.JPG
done
0
 
TintinCommented:
amendment to ghostdog's suggestion

Add

#!/bin/ksh

or

#!/bin/bash

to the top of the script, otherwise it may not work.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now