ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Recursively look in multiple folders and find files with the same name ignoring the extension

    IT Discussion
    file sorting linux command line
    4
    10
    622
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DustinB3403D
      DustinB3403
      last edited by

      Hey guys,

      I have a need to browse through multiple sub-directories and export a list of all files with the same name, ignoring the extension.

      Ideally I'd like it to print out like

      file1.wav
      file1.raw
      file2.jpg
      file2.mp4

      You get the idea, anyways anyone know of how to do this easily?

      1 Reply Last reply Reply Quote 0
      • coliverC
        coliver
        last edited by

        Windows, Linux, or Mac?

        1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller
          last edited by

          On Linux...

          find . -name something.*
          
          1 Reply Last reply Reply Quote 0
          • DustinB3403D
            DustinB3403
            last edited by

            Hrm, so I thought that, but I don't think that is going to work the way that I want it too.

            Ideally I'd like it to export the list of all files with the same name in groups like outlined in the OP.

            So

            • file1.wav
            • file1.raw
            • file2.jpg
            • file2.mp4

            I think what scott mentioned means I would have to add the file names to the command, which I don't want to do (it would be insanely tedious to try this).

            1 Reply Last reply Reply Quote 0
            • EddieJenningsE
              EddieJennings
              last edited by

              Sounds like you want to use sort

              find /kvm -type f | sort

              fd8ba3ea-8f89-442b-bb77-1d746ff3ae40-image.png

              DustinB3403D 1 Reply Last reply Reply Quote 0
              • DustinB3403D
                DustinB3403 @EddieJennings
                last edited by

                @EddieJennings Yeah I do, but I want to sort based on the file name.

                If I have the below

                somefolder1\file1.wav
                somefolder1\freakshow.mp4
                somefolder2\file1.mpg
                

                I want the output like

                somefolder1\file1.wav
                somefolder2\file1.mpg
                
                somefolder1\freakshow.mp4
                

                The reason I want this is because I'm trying to find corresponding files that relate to each other across directories.

                1 Reply Last reply Reply Quote 0
                • EddieJenningsE
                  EddieJennings
                  last edited by

                  I have an idea. Let me tinker for a bit.

                  1 Reply Last reply Reply Quote 0
                  • EddieJenningsE
                    EddieJennings
                    last edited by EddieJennings

                    #!/bin/bash
                    
                    echo "Enter the full path of the root directory to search"
                    read ROOT_DIRECTORY
                    
                    ALL_FILES=$(find $ROOT_DIRECTORY -type f)
                    
                    for i in $ALL_FILES; do
                        INDFILE=$(echo $i | rev | cut -d '/' -f 1 | cut -d '.' -f 2- | rev)
                        echo $INDFILE >> /tmp/tempfilefordustin
                    done
                    
                    UNIQUE_FILE_NAMES=$(cat /tmp/tempfilefordustin | sort -u)
                    
                    for j in $UNIQUE_FILE_NAMES; do
                        find $ROOT_DIRECTORY -type f -name "$j.*" | sort #not sure if sort is needed
                    done
                    
                    rm /tmp/tempfilefordustin
                    

                    Some man pages and a little Dr. Google + Stackoverflow for the rev idea (never used that before) was enough information to make that. Initial tests were positive.

                    Edit: Added a fix that I pushed up to Gitlab.

                    1 Reply Last reply Reply Quote 3
                    • EddieJenningsE
                      EddieJennings
                      last edited by EddieJennings

                      And if you want that space between each unique file name add an echo "" line just before the final done.

                      1 Reply Last reply Reply Quote 0
                      • EddieJenningsE
                        EddieJennings
                        last edited by

                        Tweaked a bit to provide an output file.

                        https://gitlab.com/EddieJennings/bash-general/-/blob/master/find_files_sort_by_filename.sh

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post