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?

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?

| improve this answer | |
  • No need grep here, you can get it with awk itself ls -lpSa| awk '! /\// && $5>1000' + Please don't parse ls output. – αғsнιη Sep 27 '17 at 7:39
  • @αғsнιη thx alot. I added this into a post – Egor Vasilyev Sep 27 '17 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.