我有一个bash函数,我经常使用它以一种很好的格式列出文件和目录。问题是,每次我执行函数时,大约需要2-3秒才能最终完成数据列表。
当我两次调用find命令时,需要双倍的时间。我想问一问,如何将find命令作为并行线程启动,然后得到输出。我认为这将使函数输出加载速度更快。我说错了吗?
剧本:
function lsa
{
# Function to stat files and folders in current dir
# Takes first argument as directory to stat
# If no directory supplied, current dir assumed
if [ -z "$1" ];then
DIR="."
else
DIR="$1"
fi
# print directories first
printf "*** DIRECTORIES *** \n"
find "$DIR" -maxdepth 1 -type d ! -name "." -printf "%M %u %g " -exec du -sh {} \; 2> /dev/null
# print non-directories second
printf "*** FILES *** \n"
find "$DIR" -maxdepth 1 ! -type d ! -name "." -printf "%M %u %g " -exec du -sh {} \; 2> /dev/null
}请告诉我。谢谢。
更新
具有更改的:
*** DIRECTORIES ***
[1] 6882
*** FILES ***
[2] 6883
[1]- Done find . -maxdepth 1 -type d ! -name "." -printf "%M %u %g " -exec du -sh {} \; 2> /dev/null > dirs
[2]+ Done find "$DIR" -maxdepth 1 ! -type d ! -name "." -printf "%M %u %g " -exec du -sh {} \; 2> /dev/null > non-dirs
// And then the files and dirs one after other没有更改的:
borg@borg-cube:~$lsa
*** DIRECTORIES ***
// All directories
*** FILES ***
// All files发布于 2016-01-29 09:38:35
通过在后台运行这两个查找命令并将它们的输出保存到不同的文件中,您不能拥有多个multi-processes线程。然后,wait查找命令完成,并将输出连接起来(首先是dirs)。
这边..。
find . -maxdepth 1 -type d ! -name "." -printf "%M %u %g " -exec du -sh {} \; 2> /dev/null > dirs &
...
find "$DIR" -maxdepth 1 ! -type d ! -name "." -printf "%M %u %g " -exec du -sh {} \; 2> /dev/null > non-dirs &
...
wait
cat dirs non-dirs
....**更新**
将cat dirs non-dirs结尾处替换为:
printf "*** DIRECTORIES *** \n"
cat dirs
printf "*** FILES *** \n"
cat non-dirshttps://stackoverflow.com/questions/35080941
复制相似问题