Jump to content

Quick command to rename files


jmos1277

Recommended Posts

So I recently decided to start using MediaBrowser for all of my movies.  I'm still in the evaluation phase trying to decide if this is the direction I want to go with my HTPC.  Anyway, one of the requirements for MediaBrowser is that all artwork be either '.jpg' or '.png'.  According to the MediaBrowser web page, '.jpeg' is not an accepted extension.  Of course, I had thousands of Folder.jpeg files and needed a way to quickly rename them all to Folder.jpg.  After some experimentation, I came up with the following command that works for all file names, including those with spaces and apostrophes:

 

find /mnt/disk1 -regex '.*\.jpeg' | while read n ; do echo "File $n" ; rename .jpeg .jpg "$n" ; done

 

This will find all files that have a '.jpeg' extension on disk1 and rename them with a '.jpg' extension.  I have amassed my collection of movie poster art and backdrops over the course of many years.  I cannot even begin to tell you how nervous I was when I hit the enter key (even though I did a ton of testing on quarantined files).  However, despite my concerns, it worked great.

 

Anyhow, I love my unRAID box and don't usually have too much to contribute to the community.  Thought this was something others might find useful.  Of course, if you want to search for '.jpeg' files in other locations, change the /mnt/disk1 to something else.

 

EDIT: fixed spelling errors.

Link to comment

I learned something new from your post. 

 

I never knew a "rename" command existed.  It is certainly not standard on older unixes.

 

The more common command to rename a file or directory is the "mv" command.    You would have had to deal with the embeded quotes, so your solution is better.

Link to comment

I'm like Joel I've always used the mv command.

 

As for your command not helping I think I might use it, but tweak it a little to find and move some files for me since I have a habit of using airvideo to encode some of my movies. So just think you did help the community. ;)

Link to comment

I'm like Joel I've always used the mv command.

 

As for your command not helping I think I might use it, but tweak it a little to find and move some files for me since I have a habit of using airvideo to encode some of my movies. So just think you did help the community. ;)

 

I typically use the mv command as well.  However, I was having a difficult time getting mv to work.  Too many special characters, spaces, etc.  I couldn't quite get the mv command to work in all cases.  ???  Rename worked like a charm.

 

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...