简体   繁体   中英

Linux command to find all the files with same name but different extension in a directory?

I am working on a project where i need to deal with lots of files with the same name but different extensions.

please suggest a command/solution to get the file name.

Thanks in advance

您的助手是find命令

find /<directory_name> -name  <file_name.\*>
find "$searchdir" -name "${filespec%.*}".\*

will find all files in $searchdir named "foo" with a file extension if $filespec is of the form "foo.bar".

Of course, if $filespec is of the form "foo.bar.baz", you will find all files named "foo.bar" with a file extension, so beware of such files.

If you want only the root filename (eg "foo.bar.baz.quux" -> "foo"), then you should use %% instead of % after the filespec variable.

If you need to strip a preceding directory name from the filespec, you could combine this with the basename utility:

find "$searchdir" -name "$(basename "${filespec%.*}")".\*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM