Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've tried every combination of backslash and asterisk and curly brackets, nothing seems to work. I'm using the terminal in OS X and I would really appreciate it if someone could steer me straight.

share|improve this question
What do you mean? Are you changing the " into ', and/or removing the .flac? Are you trying to make this a bulk command, or just this one file? – evan.bovie May 22 '12 at 1:02
My humble thanks to STATUS__ACCESS. This started as Windows not liking the " on a Mac OS X networked drive, probably due to some changes in Lion. I figured (wrongly) that this would be an opportunity to learn more about BASH scripting with a quick rename. – zoltanzylox May 22 '12 at 3:52
up vote 0 down vote accepted

You could use $() in order to task tr to do that conversion, then strip the file extension in a second step. It would look something similar to:

# Say FNAME is the variable that stores your original file name
# Convert the double quotes to single quotes:
SQFNAME=$(echo $FNAME|tr '""' "''")
# or, as an alternative in pure Bash (mind the shell character escaping):
SQFNAME=echo ${FNAME//\"/\'}
# then simply strip the extension
# or, if you wanted to remove the extension delimited by the _last_ dot
# or, if you wanted to remove the extension delimited by the _first_ dot

The "new" converted file name will be in the NEWFNAME variable now.

Proof of concept:

#!/usr/bin/env bash
FNAME="\"A\" Train.flac"
echo "Unchanged name: $FNAME"
echo "Converted quotes: $SQFNAME"
echo "New file name: $NEWFNAME"

Execution yields:

$ bash
Unchanged name: "A" Train.flac
Converted quotes: 'A' Train.flac
New file name: 'A' Train
share|improve this answer

I would use the prename Perl script that comes with most Perl installations (linked to rename in e.g. Debian based distributions, but on e.g. Fedora another rename is present, so research the case first if you are not sure, or just use prename as below):

prename 's/"/'\''/g' \"A\"\ Train.flac

The right tool for the right job.

To get a literal ', I first stop the current quoting environment, then escape a ', then start the quoting environment again.

I guess you don't really want to strip the file name extension and the question is just ambiguously worded, but if you do:

prename 's/"/'\''/g; s/\..*$//' \"A\"\ Train.flac


prename 's/"/'\''/g; s/\.flac$//' \"A\"\ Train.flac

Use the -n switch to just view the changes without applying them if you want to test the commands beforehand.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.