Recursively look in multiple folders and find files with the same name ignoring the extension
-
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.mp4You get the idea, anyways anyone know of how to do this easily?
-
Windows, Linux, or Mac?
-
On Linux...
find . -name something.*
-
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).
-
Sounds like you want to use
sort
find /kvm -type f | sort
-
@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.
-
I have an idea. Let me tinker for a bit.
-
#!/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.
-
And if you want that space between each unique file name add an
echo ""
line just before the finaldone
. -
Tweaked a bit to provide an output file.
https://gitlab.com/EddieJennings/bash-general/-/blob/master/find_files_sort_by_filename.sh