shell脚本-S和-Sd代码无法正常工作

时间:2016-10-10 20:46:24

标签: shell

我有以下代码:

#Option -s for each set of files with the same name, presents sorted by size#

elif [ $1 = "-S" ]
then
    shift
    for i in $*
    do
        find $i -type f -print|while read F1
            do

                basename "${F1}"
            done | sort | uniq -d | while read F2
            do
                    find $i -type f -name "${F2}" -exec ls -l -S -R '{}' \;
            done        
        done

#Option -d performs sorting in descending order.

elif [ $1 = "-d" ]
then
    shift
    for i in $*
    do
        find $i -type f -print|while read F1
            do

                basename "${F1}"
            done | sort | uniq -d | while read F2
            do
                    find $i -type f -name "${F2}" -exec ls -l '{}' \;
            done        
        done

我应该使用-S命令按大小打印它们,然后使用-Sd按降序打印它们。我的输出似乎没有这样做。此时我无法弄清楚代码中的错误。

-rw-r--r-- 1 quetzal quetzal 33 Out  7 20:27 aa/cc/t1
-rw-r--r-- 1 quetzal quetzal 8 Out  7 20:36 aa/t1
-rw-r--r-- 1 quetzal quetzal 0 Out  8 08:16 aa/cc/t2
-rw-r--r-- 1 quetzal quetzal 0 Out  8 08:15 aa/t2
-rw-r--r-- 1 quetzal quetzal 16 Out  8 08:16 aa/cc/t4
-rw-r--r-- 1 quetzal quetzal 0 Out 10 12:53 aa/dd/t4

1 个答案:

答案 0 :(得分:0)

反转这样的排序:

elif [ $1 = "-d" ]
then
shift
for i in $*
do
    find $i -type f -print|while read F1
        do

            basename "${F1}"
        done | sort -r | uniq -d | while read F2
        do
                find $i -type f -name "${F2}" -exec ls -l '{}' \;
        done        
    done