Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6957311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:59:05+00:00 2026-05-27T14:59:05+00:00

I’m developing a simple launchdaemon that copies files from one directory to another. I’ve

  • 0

I’m developing a simple launchdaemon that copies files from one directory to another. I’ve gotten the files to transfer over fine.

I just want the files in the directory to be .mp3’s instead of .dat’s

Some of the files look like this:

6546785.8786.dat
3678685.9834.dat
4658679.4375.dat

I want them to look like this:

6546785.8786.mp3
3678685.9834.mp3
4658679.4375.mp3

This is what I have at the end of the bash script to rename the file extensions.

cd $mp3_dir
mv *.dat *.mp3
exit 0

Problem is the file comes out as *.mp3 instead of 6546785.8786.mp3

and when another 6546785.8786.dat file is imported to $mp3_dir, the *.mp3 is overwritten with the new .mp3

I need to rename just the .dat file extensions to .mp3 and keep the filename.

Ideas? Suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:59:06+00:00Added an answer on May 27, 2026 at 2:59 pm

    Try:

    for file in *.dat; do mv "$file" "${file%dat}mp3"; done
    

    Or, if your shell has it:

    rename .dat .mp3 *.dat
    

    Now, why your command didn’t work: first of all, it is more than certain that you only had one file in your directory when it was renamed to *.mp3, otherwise mv would have failed with *.mp3: not a directory.

    And mv does NOT do any magic with file globs, it is the shell which expands globs. Which means, if you had this file in the directory:

    t.dat
    

    and you typed:

    mv *.dat *.mp3
    

    the shell would have expanded *.dat to t.dat. However, as nothing would match *.mp3, the shell would have left it as is, meaning the fully expanded command is:

    mv t.dat *.mp3
    

    Which will create a file named, literally, *.mp3.

    If, on the other hand, you had several files named *.dat, as in:

    t1.dat t2.dat
    

    the command would have expanded to:

    mv t1.dat t2.dat *.mp3
    

    But this will fail: if there are more than two arguments to mv, it expects the last argument (ie, *.mp3) to be a directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.