查找文件并执行命令 [英] Find files and execute command

查看:69
本文介绍了查找文件并执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多rar档案,这些档案被组织在单个文件夹中,并希望通过脚本将它们全部解压缩.

I have a lot of rar archives structured in individual folders and would like to script unpacking them all.

我在弄清楚应该怎么做时遇到麻烦,需要一些帮助.

I'm having trouble figuring out how it should be done and need some help.

#!/bin/bash
## For all inodes
for i in pwd; do
    ## If it's a directory
    if [ -d "$i" ] then
        cd $i

        ## Find ".rar" file
        for [f in *.rar]; do
            ./bin/unrar x "$f" # Run unrar command on filename
            cd ..
        done
    done
done

我对bash脚本不熟悉,我认为代码不只一次是错误的.但是我想这应该是基本结构

I am not familiar with bash scripting and I assume the code is wrong more than once. But I guess this should be the basic structure

推荐答案

您可以使用 find 命令:

You can use the find command:

find -name '*.rar' -exec unrar x {} \;

find提供了选项exec,它将在找到的每个文件上执行该命令.

find offers the option exec which will execute that command on every file that was found.

这篇关于查找文件并执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆