2

を使用して既に実行しましたbashが、 を使用してこのサブディレクトリの名前またはパスを取得するにはどうすればよいですかtcsh。後で、このサブディレクトリ内のすべてのファイルの合計サイズをカウントする必要があります。助けてください。

例えば:

someDirectory
--firstDirectory
----file11.txt
----file12.txt
----file13.txt
--secondDirectory
----file21.txt
--thirdDirectory
----file31.txt
----file32 .txt
----file33.txt
----file34.txt
----file35.txt

その結果、サードディレクトリへのパスを取得したいのですが、ほとんどのファイルが含まれているためです。

アップデート

Bash ソリューション

#!/bin/bash -f 

declare -i maxcount=0
declare -i count
declare maxdirectory

find someFolder -type d | while read DIR;
    do let count=`(ls $DIR | wc -w)`
    if(($count > $maxcount)); then 
        let maxcount=count 
        maxdirectory="$DIR"
    fi 
done

アップデート

Tcsh ソリューション

cd $1
foreach x(*)
    if(-d $x) then
    set count = `(ls $x -1 | wc -l)`
        if($count > $maxcount) then
            set directory = $x
            set maxcount = $count
        endif
    endif
end
4

4 に答える 4

0

カウンター=-1;

私のためにls -ltr | grep ^d | awk '{ print $NF }'

行う

    count=`ls -l $i | grep ^- | wc -l`

    if [[ $count -gt $counter ]]; then
            counter=$count
            Directory=$i
    fi

終わり

エコー $ ディレクトリ

于 2015-05-13T12:53:36.493 に答える
0

次のようなことができます。

foreach f ( `find someFolder -type d` )
    echo `find $f -maxdepth 1 -type f | wc -w` $f >> tmp
end
set a = `sort -rn tmp | head -n1`
set num = $a[1]
set dir = $a[2]
于 2013-03-04T21:31:47.693 に答える