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 828531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:44:21+00:00 2026-05-15T03:44:21+00:00

I have found a useful shell script that shows all files in a directory

  • 0

I have found a useful shell script that shows all files in a directory recursively.

Where it prints the file name echo "$i"; #Display File name.

I would instead like to run an ffmpeg command on non MP3 files, how can I do this? I have very limited knowledge of shell scripts so I appreciate if I was spoon fed! 🙂

//if file is NOT MP3

ffmpeg -i [the_file] -sameq [same_file_name_with_mp3_extension]

//delete old file

Here is the shell script for reference.

DIR="."

function list_files()
{
    if !(test -d "$1")  
    then echo $1; return;
    fi

    cd "$1"
    echo; echo `pwd`:; #Display Directory name

    for i in *
    do
               if test -d "$i"  #if dictionary
                then  
                          list_files "$i" #recursively list files
                  cd ..
                else
            echo "$i"; #Display File name
                fi

    done
}

if [ $# -eq 0 ]
then list_files .
exit 0
fi

for i in $*
do
    DIR="$1"
    list_files "$DIR"
    shift 1 #To read next directory/file name
done
  • 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-15T03:44:22+00:00Added an answer on May 15, 2026 at 3:44 am

    You can do the same with a find one-liner. Assuming the files you want to process are all wav:

    find /path/ -type f -name "*wav" -exec ffmpeg -i {} -sameq {}.mp3 \;
    

    If you want to find “rm” files, and delete them after conversion:

    find /path/ -type f -name "*.rm" -exec ffmpeg -i {} -sameq {}.mp3 && rm {} \;
    

    That said, if you want to do it with the shell script you showed, take the line that says

    echo "$i";
    

    replace it with this:

    ffmpeg -i "$i" -sameq "$i".mp3
    

    $i is a variable. A few lines up, you have:

    for i in *
    

    this basically means “for every element in * (which in turn stands for all files in the current directory, it’s what’s called a “shell expansion”), put the name of the element/file in the variable i, and then execute all the code between “do” and “done” “. So for each iteration, i will contain the name of one of the files in this directory.

    There’s also a section that tests whether i is a directory and if so, it recursively lists its contents.

    A quick final note: the \; at the end of the find command IS significant and it NEEDS to have a space before the backslash, otherwise it won’t work.

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

Sidebar

Related Questions

I currently have this useful code that I found elsewhere on StackOverflow: form.DrawToBitmap(bmp, new
Recently I came across a gcc extension that I have found rather useful: __attribute__(cleanup)
What techniques that people have found useful using Clojure, Scala, JRuby, build tools, etc.
I have found -E very useful to see preprocessor output and debug macros, and
Having used storyboards for a while now I have found them extremely useful however,
I have found this answer really useful. It helps me plot network/graphs and select
I have found the following command in AWK useful in Vim :'<,'>!awk '{ print
I have found SocketSniff to be very useful for troubleshooting network applications (like web
I've scored the internet for sources and have found a lot of useful information,
I'm learning xUnit and so far, have found it to be a most useful

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.