用于过滤文件的Unix脚本 [英] Unix script to filter files
问题描述
你好,
我必须写一个unix脚本,我真的不熟悉它并需要帮助。
我有一个根目录,里面有很多其他目录。
每个目录都包含txt文件。
我必须通过所有目录目录和所有文件。
如果文件包含短语文件信息,我想保留文件。如果文件不包含它,我想删除该文件。
然后,如果目录的所有文件都已删除,并且目录为空,我想删除该目录。 br />
如何编写这样的脚本?
谢谢
hello,
I have to write a unix script and I am really not familiar with it and need help.
I have a root directory, inside it I have a lot of other directories.
Each directory contains txt files.
I have to go through all the directories and all the files.
If a file contains the phrase "file information" I want to keep the file. If the file does not contain it, I want to delete the file.
Then, If all the files of a directory have been deleted, and the directory is empty, I want to delete the directory.
How can I write a script like that?
Thanks
推荐答案
您的任务非常明确。由于您不是shell脚本专家,我建议您使用除法,Google和impra方法:例如,您可以开始搜索如何执行在shell脚本中进行递归查找 [ ^ ]。
Your task is fairly articulated. Since you are not an expert on shell scripting I suggest you the divide, Google et impera approach: for instance, you could start searching for how to perform a recursive find in shell script[^].
这篇关于用于过滤文件的Unix脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!