How to find files dynamically and copy them to a directory in linux

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Trying to find these files and copy them to a directory (test_dir);
abc-1.0.zip
kncb-1.0.zip
jenk-1.1.zip
I would like to find all these files dynamically and copy them to a directory. I have tried the below command but it copies only last file(jenk*.zip) only, need a command which copies all the above files to a directory mentioned (test_dir);
find / -type f -name "*abc*.zip" -o -name "*kncb*.zip" -o -name "*jenk*.zip" ! -path '*/test_dir/*.jar' -exec cp -ar ./test_dir ;
linux find cp
add a comment |Â
up vote
0
down vote
favorite
Trying to find these files and copy them to a directory (test_dir);
abc-1.0.zip
kncb-1.0.zip
jenk-1.1.zip
I would like to find all these files dynamically and copy them to a directory. I have tried the below command but it copies only last file(jenk*.zip) only, need a command which copies all the above files to a directory mentioned (test_dir);
find / -type f -name "*abc*.zip" -o -name "*kncb*.zip" -o -name "*jenk*.zip" ! -path '*/test_dir/*.jar' -exec cp -ar ./test_dir ;
linux find cp
are you guaranteed that there'll only be one of each of those?
â Jeff Schaller
Sep 25 at 1:54
why are you recursively copying (-r) when you're looking (presumably) for single files?
â Jeff Schaller
Sep 25 at 1:55
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Trying to find these files and copy them to a directory (test_dir);
abc-1.0.zip
kncb-1.0.zip
jenk-1.1.zip
I would like to find all these files dynamically and copy them to a directory. I have tried the below command but it copies only last file(jenk*.zip) only, need a command which copies all the above files to a directory mentioned (test_dir);
find / -type f -name "*abc*.zip" -o -name "*kncb*.zip" -o -name "*jenk*.zip" ! -path '*/test_dir/*.jar' -exec cp -ar ./test_dir ;
linux find cp
Trying to find these files and copy them to a directory (test_dir);
abc-1.0.zip
kncb-1.0.zip
jenk-1.1.zip
I would like to find all these files dynamically and copy them to a directory. I have tried the below command but it copies only last file(jenk*.zip) only, need a command which copies all the above files to a directory mentioned (test_dir);
find / -type f -name "*abc*.zip" -o -name "*kncb*.zip" -o -name "*jenk*.zip" ! -path '*/test_dir/*.jar' -exec cp -ar ./test_dir ;
linux find cp
linux find cp
edited Sep 25 at 1:55
Jeff Schaller
33.3k850112
33.3k850112
asked Sep 25 at 1:40
itgeek
151
151
are you guaranteed that there'll only be one of each of those?
â Jeff Schaller
Sep 25 at 1:54
why are you recursively copying (-r) when you're looking (presumably) for single files?
â Jeff Schaller
Sep 25 at 1:55
add a comment |Â
are you guaranteed that there'll only be one of each of those?
â Jeff Schaller
Sep 25 at 1:54
why are you recursively copying (-r) when you're looking (presumably) for single files?
â Jeff Schaller
Sep 25 at 1:55
are you guaranteed that there'll only be one of each of those?
â Jeff Schaller
Sep 25 at 1:54
are you guaranteed that there'll only be one of each of those?
â Jeff Schaller
Sep 25 at 1:54
why are you recursively copying (
-r) when you're looking (presumably) for single files?â Jeff Schaller
Sep 25 at 1:55
why are you recursively copying (
-r) when you're looking (presumably) for single files?â Jeff Schaller
Sep 25 at 1:55
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
You need to apply ( ) around your OR construct.
An explanation can be found in the man page:
Please note that -a, when specified implicitly (for example by two
tests appearing without an explicit operator between them) or
explicitly, has higher precedence than -o. This means that find . -name
afile -o -name bfile -print will never print afile.
Example:
touch afile bfile
Without ( ):
find . -name afile -o -name bfile -print
./bfile
which has an implicit -a between -name bfile and -print:
find . -name afile -o -name bfile -a -print
./bfile
With ( ) the result is as expected:
find . ( -name afile -o -name bfile ) -print
./afile
./bfile
Your implicit -a lies between -o -name "*jenk*.zip" and ! -path '*/test_dir/*.jar'.
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You need to apply ( ) around your OR construct.
An explanation can be found in the man page:
Please note that -a, when specified implicitly (for example by two
tests appearing without an explicit operator between them) or
explicitly, has higher precedence than -o. This means that find . -name
afile -o -name bfile -print will never print afile.
Example:
touch afile bfile
Without ( ):
find . -name afile -o -name bfile -print
./bfile
which has an implicit -a between -name bfile and -print:
find . -name afile -o -name bfile -a -print
./bfile
With ( ) the result is as expected:
find . ( -name afile -o -name bfile ) -print
./afile
./bfile
Your implicit -a lies between -o -name "*jenk*.zip" and ! -path '*/test_dir/*.jar'.
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
add a comment |Â
up vote
2
down vote
You need to apply ( ) around your OR construct.
An explanation can be found in the man page:
Please note that -a, when specified implicitly (for example by two
tests appearing without an explicit operator between them) or
explicitly, has higher precedence than -o. This means that find . -name
afile -o -name bfile -print will never print afile.
Example:
touch afile bfile
Without ( ):
find . -name afile -o -name bfile -print
./bfile
which has an implicit -a between -name bfile and -print:
find . -name afile -o -name bfile -a -print
./bfile
With ( ) the result is as expected:
find . ( -name afile -o -name bfile ) -print
./afile
./bfile
Your implicit -a lies between -o -name "*jenk*.zip" and ! -path '*/test_dir/*.jar'.
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You need to apply ( ) around your OR construct.
An explanation can be found in the man page:
Please note that -a, when specified implicitly (for example by two
tests appearing without an explicit operator between them) or
explicitly, has higher precedence than -o. This means that find . -name
afile -o -name bfile -print will never print afile.
Example:
touch afile bfile
Without ( ):
find . -name afile -o -name bfile -print
./bfile
which has an implicit -a between -name bfile and -print:
find . -name afile -o -name bfile -a -print
./bfile
With ( ) the result is as expected:
find . ( -name afile -o -name bfile ) -print
./afile
./bfile
Your implicit -a lies between -o -name "*jenk*.zip" and ! -path '*/test_dir/*.jar'.
You need to apply ( ) around your OR construct.
An explanation can be found in the man page:
Please note that -a, when specified implicitly (for example by two
tests appearing without an explicit operator between them) or
explicitly, has higher precedence than -o. This means that find . -name
afile -o -name bfile -print will never print afile.
Example:
touch afile bfile
Without ( ):
find . -name afile -o -name bfile -print
./bfile
which has an implicit -a between -name bfile and -print:
find . -name afile -o -name bfile -a -print
./bfile
With ( ) the result is as expected:
find . ( -name afile -o -name bfile ) -print
./afile
./bfile
Your implicit -a lies between -o -name "*jenk*.zip" and ! -path '*/test_dir/*.jar'.
answered Sep 25 at 4:59
nst0022
1062
1062
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
add a comment |Â
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
Getting an error when I run this from jenkins; find / (-name "abc.zip" -o -name "kncb.zip" -o -name "jenk.zip" ) ! -path '/test_dir/.jar' -exec cp -ar ./test_dir ; find: invalid expression; you have used a binary operator '-o' with nothing before it.
â itgeek
Sep 25 at 13:57
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471215%2fhow-to-find-files-dynamically-and-copy-them-to-a-directory-in-linux%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
are you guaranteed that there'll only be one of each of those?
â Jeff Schaller
Sep 25 at 1:54
why are you recursively copying (
-r) when you're looking (presumably) for single files?â Jeff Schaller
Sep 25 at 1:55