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
  • 193,181
  • 53
  • 473
  • 722
kestrel
  • 43
  • 6
  • 1
    related: [What's a command line way to find large files/directories to remove and free up space?](https://askubuntu.com/q/36111/507051) – dessert Mar 07 '18 at 19:13
  • You may also want to read [How can I get help on terminal commands?](https://askubuntu.com/q/991946/507051). – dessert Mar 07 '18 at 21:17

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,392
  • 12
  • 115
  • 163