Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux 'find' only for current folder and specified ones

I need to find files in the current folder (non-recursively) and some other folders (recursively). For example I have a tree structure like:

  • folder1/
  • folder2/
    • folder2-1/
      • file2-1.php
  • folder3/
    • file3-1.php
  • file1.php
  • file2.php

I want to find files file1.php, file2.php and file2-1.php only. So, search in the root + folder2/ recursively.

All the resources I could find describe either

find . -maxdepth 1 -iname "*.php" // gives `file1.php` and `file2.php`

or

find folder2 -iname "*.php" // gives me `file2-1.php`

So:

Q. How do I combine these commands?

P.S. I should be able to send the list of the found files further in the command line as well (for example to xgettext).

like image 995
spliter Avatar asked Jul 14 '26 07:07

spliter


1 Answers

Like this?

( find . -maxdepth 1 -iname "*.php"; find folder2 -iname "*.php") | xgettext
like image 141
tink Avatar answered Jul 17 '26 18:07

tink



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!