[英]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". 如果
$filespec
的格式为“ foo.bar”,它将在$searchdir
找到名为“ foo”且带有文件扩展名的所有文件。
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. 当然,如果
$filespec
的格式为“ foo.bar.baz”,则将找到所有带有文件扩展名的名为“ foo.bar”的文件,因此请注意此类文件。
If you want only the root filename (eg "foo.bar.baz.quux" -> "foo"), then you should use %%
instead of %
after the filespec
variable. 如果只需要根文件名(例如“ foo.bar.baz.quux”->“ foo”),则应在
filespec
变量后使用%%
而不是%
。
If you need to strip a preceding directory name from the filespec, you could combine this with the basename
utility: 如果需要从filespec中删除先前的目录名称,则可以将其与
basename
实用程序结合使用:
find "$searchdir" -name "$(basename "${filespec%.*}")".\*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.