0

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.

masher
  • 53
  • 9
  • 1
    StackOverflow is dedicated to helping solve programming code problems. Your Q seems more appropriate for https://superuser.com or https://unix.stackexchange.com , but read their help section regarding on-topic questions . AND please read [Help On-topic](https://stackoverflow.com/Help/On-topic) and [Help How-to-ask](https://stackoverflow.com/Help/How-to-ask) before posting more Qs here. Good luck. – shellter Dec 04 '19 at 17:54
  • Not clear, see [mcve] – oguz ismail Dec 04 '19 at 18:00
  • ANSWERED - https://superuser.com/questions/1507449/copy-binaries-from-sourcedir-and-its-subdirs-to-destdir – masher Jan 24 '20 at 15:56

1 Answers1

2

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 \;
dash-o
  • 13,723
  • 1
  • 10
  • 37
  • Command-line tool usage (for tools that aren't software-development-specific) isn't generally topical on SO anyhow. – Charles Duffy Dec 04 '19 at 20:39
  • Thanks, that was close enough. This is what worked. `code` find /my/sourcedir/ -mindepth 2 -type f -not \( -iname "excludeDir" -or -iname '*.c' -or -iname '*.h' -or -iname '.ssh' -or -iname "Makefile" \) -exec cp {} /my/destdir \; – masher Dec 04 '19 at 21:36