bashbinaries

copy binaries from /sourcedir and its subdirs to /destdir


Copy all binaries from /sourcedir to /destdir. Basically, all files with: no extension, and all files with *.a, *.so, *.ko, exclude from copy: *.c, *.h files. Copy files from all subdirs except the sub-directory named "excludeDir".

I have tried the following from bash:

find /my/sourcedir/ -mindepth 2 -type f -not -iname "excludeDir" -or "*.c" -or "*.h" -or "makefile" -print -exec cp {} /my/destdir \;

bash yields the following error:

find: paths must precede expression: `*.c'

The command does not throw an error until attempting to exclude files/sub-directory.


Solution

  • Find expect condition on the file name to follow -name pattern. This will be needed for the '*.c', '*.h' and 'Makefile' terms. (formatting for readability only, keep everything on one line).

    find /my/sourcedir/ -mindepth 2 -type f -not '(' -iname "excludeDir"
        -or -name '*.c'
        -or -name '*.h'
        -or -name "makefile" ')' -print -exec cp {} /my/destdir \;