4

I want to list all the files with .sh extension and size greater than 5kb with the same directory. what I know is how to list all files with a specific size by:

find . -size +5k -exec ls -l {} \+

and how to list all the files with specific extension by:

ls *.sh

what do I need to know is how to do both simultaneously?

muru
  • 197,895
  • 55
  • 485
  • 740
kestrel
  • 43

1 Answers1

9

find has a -name option to perform a test on the file name, e.g. to list every file with an .sh extension:

find -type f -name "*.sh"

Use -iname instead if you want it to be case-insensitive, e.g. also find .Sh or .SH. You can simply combine this with -size:

find -type f -name "*.sh" -size +5k

find also has an -ls option to display file stats, while your -exec approach is totally OK it may be faster and is much easier to type:

find -type f -name "*.sh" -size +5k -ls
dessert
  • 39,982