• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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