Bash 遍历目录列表并生成 md5
bash 脚本会是这样的:
- 遍历一个目录,并将所有子目录放入一个数组中
- 对于每个目录,生成该目录内文件的 md5
和 另外,必须生成 md5sum 的文件不需要生成始终具有相同的名称和路径。然而,模式总是相同的:
/var/mobile/Applications/{ the dir name here is taken from the array }/{some name}.app/{ binary, who's name is the same as it's parent dir, but without the .app extension }
我以前从未使用过 bash(也从来不需要),所以这可能是非常简单和新手的事情。有人有主意吗?从路径可以看出,它被设计为在 iDevice 上运行。
What would be the bash script that:
- Goes through a directory, and puts all the sub-directories in an array
- For each dir, generate an md5 sum of a file inside that dir
Also, the file who's md5sum has to be generated doesn't always have the same name and path. However, the pattern is always the same:
/var/mobile/Applications/{ the dir name here is taken from the array }/{some name}.app/{ binary, who's name is the same as it's parent dir, but without the .app extension }
I've never worked with bash before (and have never needed to) so this may be something really simple and nooby. Anybody got an idea? As can be seen by the path, this is designed to be run on an iDevice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个,我希望代码是简单的。值得解释的两件事是:
${app##*/}
,它使用##
运算符去除与表达式*/匹配的最长前缀
。${appdirname%.app}
,它使用%
运算符去除与表达式.app
匹配的最短后缀。 (您也可以使用%%
(去掉最长的后缀)而不是%
,因为模式.app
始终是四个字符长。)Try this, I hope the code is straight-forward. The two things worth explaining are:
${app##*/}
, which uses the##
operator to strip off the longest prefix matching the expression*/
.${appdirname%.app}
, which uses the%
operator to strip off the shortest suffix matching the expression.app
. (You could have also used%%
(strip longest suffix) instead of%
, since the pattern.app
is always four characters long.)尝试类似的操作:
上面将显示所有应用程序的所有
Info.plist
文件的 md5 校验和,例如:Try something like:
the above will show md5 checksum for all
Info.plist
files for all applications, like:Bash 非常简单,但您需要了解系统的 cli 工具。
用于递归打印目录中所有文件的 md5 哈希值:
如果您只想列出目录树:
您可以使用以下命令生成列表:
使用“for”迭代列表:
如果您是 bash 新手:
Bash is very easy but you need to know the cli-tools of your system.
For to print the md5 hash of all files of the a directory recursively:
If you only want to list the tree of directories:
You can generate a list with:
Use "for" for iterate the list:
If you are a newbie in bash: