1

I'm looking for a way to scan a directory recursively and print out all instances of any file that ends ".qfx". Thus, for a given directory:

somedir/
    fizz.qfx
    buzz.qfx
    blah/
        foo.qfx
        widget.js
        meh/
            bar.qfx
            derp.gif

The output would be:

somedir/fizz.qfx
somedir/buzz.qfx
somedir/blah/foo.qfx
somedir/blah/meh/bar.qfx

I'm on Ubuntu so no preference in shell, python, perl, etc. Best attempt so far is:

find -name ".qfx" somedir

But getting the following error:

find: paths must precede expression: .
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec][path...] [expression]

Any ideas? Thanks in advance!

1
  • Sorry, but asking this question is just ultimately lazy (despite it being verbose and nicely (time-consuming?) formatted. The error tells you exactly what you're doing wrong.
    – tink
    Jun 19, 2013 at 0:25

3 Answers 3

3

it tells you to put the directory before the -name expression. Also, you need a * to match for all files:

find somedir -name "*.qfx" 
2
find /u02/fullbackup -name *.bck -print
find: paths must precede expression: arc_381465332_OSOS_20160219_2879_1.bck
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

solution:

find /u02/fullbackup -name '*.bck' -print

/u02/fullbackup/dbf_381465332_OSOS_20160219_2872_1.bck
/u02/fullbackup/arc_381465332_OSOS_20160219_2882_1.bck
/u02/fullbackup/arc_381465332_OSOS_20160219_2892_1.bck
/u02/fullbackup/arc_381465332_OSOS_20160219_2894_1.bck
/u02/fullbackup/arc_381465332_OSOS_20160219_2891_1.bck
/u02/fullbackup/arc_381465332_OSOS_20160219_2885_1.bck
/u02/fullbackup/dbf_381465332_OSOS_20160219_2871_1.bck
/u02/fullbackup/arc_381465332_OSOS_20160219_2888_1.bck
1

In the case you're using zsh as shell, you can also use ls **/*.qfx, which is pretty useful.

2
  • 1
    also works in bash if the globstar option is enabled: shopt -s globstar
    – mata
    Jun 18, 2013 at 23:29
  • @mata true, however that is bash version 4 or later. Jun 19, 2013 at 4:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .