简体   繁体   English

Linux命令在目录中查找具有相同名称但扩展名不同的所有文件?

[英]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.

相关问题 Linux 命令行:在包含特定文本的目录树中查找具有特定扩展名的所有文件 - Linux command line: Find all files with a certain extension in a directory tree containing specific text 在Linux中,如何查找相同目录下具有相同扩展名的文件并将其复制到一个目录中? - How does one find and copy files of the same extension, in different directories, to a single directory in linux? Linux命令为目录中的所有文件提供文件扩展名 - Linux command to give all files in a directory a file extension 查找所有扩展名为.sh .cpp .c的文件,并将其复制到我的桌面目录中,如果存在同名文件,则将其重命名 - find all files with .sh .cpp .c extension and copy them to a directory in my desktop, if there is a file with the same name, rename it Bash命令查找名称相同但扩展名不同的文件 - Bash command to find files who have the same name but not the same extension 如何查找所有不具有名称相同但扩展名不同的匹配文件的文件 - how to find all files that dont have a matching file with the same name but different extension 仅在下面的目录中查找和同名文件,然后复制到其他目录 - Find and files of same name only in directory below and copy to a different directory 将所有文件夹和文件移动到 Linux 目录中具有相同主题名称的文件夹中 - move all the folders and files to the folder with the same subject name in the directory Linux 如何使用diff命令在目录中查找具有相同名称的文件? - How to find files with same name part in directory using the diff command? 在python中查找所有linux文件的通用目录 - Find general directory of all linux files in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM