How can I display all files greater than 10k bytes in my current directory and it’s subdirectories.
Tried ls -size +10k but that didn’t work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
find . -size +10k -exec ls -lh {} \+the first part of this is identical to @sputnicks answer, and sucesffully finds all files in the directory over 10k (don’t confuse k with K), my addition, the second part then executes
ls -lhor ls that lists(-l) the files by human readable size(-h). negate the h if you prefer. of course the{}is the file itself, and the\+is simply an alternative to\;which in practice
\;would repeat or:ls -l found.file; ls -l found.file.2; ls -l found.file.3where
\+display it as one statement or:ls -l found.file found.file.2 found.file.3more on \; vs + with
findAdditionaly, you may want the listing ordered by size. Which is relatively easy to accomplish. I would at the
-soption tols, sols -lsand then pipe it tosort -nto sort numericallywhich would become:
find . -size +10k -exec ls -ls {} \+ | sort -nor in reverse order add an -r :
find . -size +10k -exec ls -ls {} \+ | sort -nrfinally, your title says find biggest file in directory. You can do that by then piping the code to
tailfind . -size +10k -exec ls -ls {} \+ | sort -n | tail -1would find you the largest file in the directory and its sub directories.
note you could also sort files by size by using -S, and negate the need for sort. but to find the largest file you would need to use head so
find . -size +10k -exec ls -lS {} \+ | head -1the benefit of doing it with -S and not
sortis one, you don’t have to typesort -nand two you can also use-hthe human readable size option. which is one of my favorite to use, but is not available with older versisions ofls, for example we have an old centOs 4 server at work that doesn’t have-h