简体   繁体   English

除了使用正则表达式外,如何忽略或排除shell中的备份文件[以〜结尾的文件]?

[英]How to ignore or exclude backup files [files ending with ~] in shell other than using regular expressions?

For example, If I want to get the md5checksum of all files in a path. 例如,如果我想获取md5checksum中所有文件的md5checksum

$ find /path/to/ -type f -print0 | xargs -0 md5sum

But the output also includes checksum of backup files. 但是输出还包括备份文件的校验和。 In general, any way to ignore backup files in shell? 通常,有什么方法可以忽略Shell中的备份文件?

Just tell find to restrict the found names to those that do not end with tilde: 只需告诉find将找到的名称限制为不以代字号结尾的名称即可:

find /path/to/ -type f ! -name '*~' -exec md5sum {} +

This does not use regular expressions ( *~ is a filename globbing pattern). 这不使用正则表达式( *~是文件名遍历模式)。

The only file name pattern that typically has a special meaning in the context of Unix shell is names starting with dot . 在Unix shell上下文中,通常具有特殊含义的唯一文件名模式是以dot开头的名称. .These files are typically considered "invisible" for default shell expansion. 这些文件通常被视为默认Shell扩展的“不可见”文件。

Different applications use different name patterns for indicating what they consider to be "backup files" (tilde ~ in the beginning or a name, in the end, .backup extension etc.). 不同的应用程序使用不同的名称模式来表示它们认为是“备份文件”的名称(开头是波浪线~或结尾是名称, .backup扩展名等)。 Unless such applications also mark such files with specific (non-standard) file attributes, the easiest way to tell them apart is by providing a file name pattern or wildcard specific for a given type of backup files. 除非此类应用程序还使用特定的(非标准)文件属性标记此类文件,否则最容易区分它们的方法是通过提供给定类型的备份文件专用的文件名模式或通配符。

In your case, find accepts file name patterns as a regular argument: -name "*~" 在您的情况下, find接受文件名模式作为常规参数: -name "*~"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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