0

I can sort the files either in descending order (of any size) or list all files greater than 1000 bytes but don't know how to sort files greater than 1000 bytes in a user specified directory.

List files greater than 1000 bytes :

for i in "$1/*" # $1 expects a directory name
do
    if [ `wc -c $i` -gt 1000 ]
        echo $i
done

List files in descending order of size :

`ls -lhS`

But how do I list all files greater than 1000 bytes in descending order of size?

1 Answers1

3

Try this:

find . -maxdepth 1 -size +1000c -type f -exec ls -lhSa '{}' +

Explanation:

-maxdepth 1 - find files only in current directory

-size +1000c - find only files greather than 1000 bytes ("c" = bytes)

-type f - find only files

-exec <command> {} + - execute command. See man find for more information

If you do not want to use find (i don't know why), you may type (thx @αғsнιη):

ls -lpSa | awk '! /\// && $5>1000'

But Why not parse ls?