为目录中的每个文件运行shell脚本 [英] Run shell script for every file in directory
本文介绍了为目录中的每个文件运行shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在目录中有一堆文件,都名为YYYY_MM_DD
I have a bunch of files in a directory all named YYYY_MM_DD
-rw-r--r-- 1 root root 480K Apr 21 13:17 2012_04_05
-rw-r--r-- 1 root root 483K Apr 21 13:17 2012_04_06
-rw-r--r-- 1 root root 484K Apr 21 13:17 2012_04_07
-rw-r--r-- 1 root root 480K Apr 21 13:17 2012_04_08
-rw-r--r-- 1 root root 344K Apr 21 13:17 2012_04_09
-rw-r--r-- 1 root root 66K Apr 21 13:17 2012_04_10
-rw-r--r-- 1 root root 461K Apr 21 13:17 2012_04_11
-rw-r--r-- 1 root root 475K Apr 21 15:09 2012_04_17
-rw-r--r-- 1 root root 480K Apr 21 15:10 2012_04_18
-rw-r--r-- 1 root root 474K Apr 21 15:10 2012_04_19
-rw-r--r-- 1 root root 474K Apr 21 15:10 2012_04_20
我有一个Shell脚本,它接受文件作为参数,并根据文件中的数据计算图形,我这样称呼脚本
I have a shell script that accepts a file as a paramater and calculates figures based on the data in the file, i call the script like this
sh Calculate.sh MyFile
我想为该目录中的每个文件运行此Shell脚本.
I want to run this shell script for every file in this directory.
xargs,我将如何去做?
How would i go about doing this, xargs ??
推荐答案
您是否尝试过执行 find
命令?
Have you tried the find
command with execution ?
我的示例将回显文件,但是您可以使用文件名作为参数来调用Shell脚本
My sample will echo the files, but you can call a shell script with the filename as a parameter
find . -maxdepth 1 -type f -exec echo {} \;
这篇关于为目录中的每个文件运行shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文