Executing command for each newline separated [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
How can I run a specific command for each find result?
5 answers
This is a newb question..I have this:
chmod u+x $(find scripts -name "*.sh")
But I believe it's only running chmod u+x for the first item in the list from find, since the results are newline separated.
How can I run chmod u+x for each item returned from the find call?
My guess is that xargs is the best way? something like this:
find scripts -name "*.sh" | xargs chmod u+x
find chmod xargs
marked as duplicate by muru, Stephen Kitt, ñÃÂsýù÷, Romeo Ninov, Evan Carroll Apr 27 at 6:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
 |Â
show 1 more comment
up vote
0
down vote
favorite
This question already has an answer here:
How can I run a specific command for each find result?
5 answers
This is a newb question..I have this:
chmod u+x $(find scripts -name "*.sh")
But I believe it's only running chmod u+x for the first item in the list from find, since the results are newline separated.
How can I run chmod u+x for each item returned from the find call?
My guess is that xargs is the best way? something like this:
find scripts -name "*.sh" | xargs chmod u+x
find chmod xargs
marked as duplicate by muru, Stephen Kitt, ñÃÂsýù÷, Romeo Ninov, Evan Carroll Apr 27 at 6:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Your belief is not accurate. What happens when you run it that makes you think it's doing that? Are there any unusual file names or file permissions?
â Michael Homer
Apr 27 at 4:55
nah no unusual filenames...wouldn't the xargs command be different than the first one? if one command, works the other shouldn't..
â Alexander Mills
Apr 27 at 5:02
Why do you think that those commands canâÂÂt both work? (Ignoring file names with whitespace etc.)
â Stephen Kitt
Apr 27 at 5:45
Uhh with the first one, since the find command returns newline separate results, I wasn't under the impression thatchmod u+x
(or any similar command) can handle that
â Alexander Mills
Apr 27 at 6:53
1
Oh,chmod
doesnâÂÂt need to handle newlines in the result of a command substitution: the shell parses everything (and it removes newlines from the output).
â Stephen Kitt
Apr 30 at 9:02
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How can I run a specific command for each find result?
5 answers
This is a newb question..I have this:
chmod u+x $(find scripts -name "*.sh")
But I believe it's only running chmod u+x for the first item in the list from find, since the results are newline separated.
How can I run chmod u+x for each item returned from the find call?
My guess is that xargs is the best way? something like this:
find scripts -name "*.sh" | xargs chmod u+x
find chmod xargs
This question already has an answer here:
How can I run a specific command for each find result?
5 answers
This is a newb question..I have this:
chmod u+x $(find scripts -name "*.sh")
But I believe it's only running chmod u+x for the first item in the list from find, since the results are newline separated.
How can I run chmod u+x for each item returned from the find call?
My guess is that xargs is the best way? something like this:
find scripts -name "*.sh" | xargs chmod u+x
This question already has an answer here:
How can I run a specific command for each find result?
5 answers
find chmod xargs
asked Apr 27 at 4:46
Alexander Mills
1,885929
1,885929
marked as duplicate by muru, Stephen Kitt, ñÃÂsýù÷, Romeo Ninov, Evan Carroll Apr 27 at 6:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Stephen Kitt, ñÃÂsýù÷, Romeo Ninov, Evan Carroll Apr 27 at 6:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Your belief is not accurate. What happens when you run it that makes you think it's doing that? Are there any unusual file names or file permissions?
â Michael Homer
Apr 27 at 4:55
nah no unusual filenames...wouldn't the xargs command be different than the first one? if one command, works the other shouldn't..
â Alexander Mills
Apr 27 at 5:02
Why do you think that those commands canâÂÂt both work? (Ignoring file names with whitespace etc.)
â Stephen Kitt
Apr 27 at 5:45
Uhh with the first one, since the find command returns newline separate results, I wasn't under the impression thatchmod u+x
(or any similar command) can handle that
â Alexander Mills
Apr 27 at 6:53
1
Oh,chmod
doesnâÂÂt need to handle newlines in the result of a command substitution: the shell parses everything (and it removes newlines from the output).
â Stephen Kitt
Apr 30 at 9:02
 |Â
show 1 more comment
Your belief is not accurate. What happens when you run it that makes you think it's doing that? Are there any unusual file names or file permissions?
â Michael Homer
Apr 27 at 4:55
nah no unusual filenames...wouldn't the xargs command be different than the first one? if one command, works the other shouldn't..
â Alexander Mills
Apr 27 at 5:02
Why do you think that those commands canâÂÂt both work? (Ignoring file names with whitespace etc.)
â Stephen Kitt
Apr 27 at 5:45
Uhh with the first one, since the find command returns newline separate results, I wasn't under the impression thatchmod u+x
(or any similar command) can handle that
â Alexander Mills
Apr 27 at 6:53
1
Oh,chmod
doesnâÂÂt need to handle newlines in the result of a command substitution: the shell parses everything (and it removes newlines from the output).
â Stephen Kitt
Apr 30 at 9:02
Your belief is not accurate. What happens when you run it that makes you think it's doing that? Are there any unusual file names or file permissions?
â Michael Homer
Apr 27 at 4:55
Your belief is not accurate. What happens when you run it that makes you think it's doing that? Are there any unusual file names or file permissions?
â Michael Homer
Apr 27 at 4:55
nah no unusual filenames...wouldn't the xargs command be different than the first one? if one command, works the other shouldn't..
â Alexander Mills
Apr 27 at 5:02
nah no unusual filenames...wouldn't the xargs command be different than the first one? if one command, works the other shouldn't..
â Alexander Mills
Apr 27 at 5:02
Why do you think that those commands canâÂÂt both work? (Ignoring file names with whitespace etc.)
â Stephen Kitt
Apr 27 at 5:45
Why do you think that those commands canâÂÂt both work? (Ignoring file names with whitespace etc.)
â Stephen Kitt
Apr 27 at 5:45
Uhh with the first one, since the find command returns newline separate results, I wasn't under the impression that
chmod u+x
(or any similar command) can handle thatâ Alexander Mills
Apr 27 at 6:53
Uhh with the first one, since the find command returns newline separate results, I wasn't under the impression that
chmod u+x
(or any similar command) can handle thatâ Alexander Mills
Apr 27 at 6:53
1
1
Oh,
chmod
doesnâÂÂt need to handle newlines in the result of a command substitution: the shell parses everything (and it removes newlines from the output).â Stephen Kitt
Apr 30 at 9:02
Oh,
chmod
doesnâÂÂt need to handle newlines in the result of a command substitution: the shell parses everything (and it removes newlines from the output).â Stephen Kitt
Apr 30 at 9:02
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
The safest way to do this is to let find
execute chmod
directly, and also to be more careful in the selection of the files:
find scripts -type f -name '*.sh' -exec chmod u+x +
This will find all regular files in or below the scripts
directory that have names that end with .sh
and will run chmod u+x
on as many of these as possible at once. It will handle possibly weird filenames without issues.
To change the permissions on only those files that needs it:
find scripts -type f -name '*.sh' ! -perm -u+x -exec chmod u+x +
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The safest way to do this is to let find
execute chmod
directly, and also to be more careful in the selection of the files:
find scripts -type f -name '*.sh' -exec chmod u+x +
This will find all regular files in or below the scripts
directory that have names that end with .sh
and will run chmod u+x
on as many of these as possible at once. It will handle possibly weird filenames without issues.
To change the permissions on only those files that needs it:
find scripts -type f -name '*.sh' ! -perm -u+x -exec chmod u+x +
add a comment |Â
up vote
1
down vote
The safest way to do this is to let find
execute chmod
directly, and also to be more careful in the selection of the files:
find scripts -type f -name '*.sh' -exec chmod u+x +
This will find all regular files in or below the scripts
directory that have names that end with .sh
and will run chmod u+x
on as many of these as possible at once. It will handle possibly weird filenames without issues.
To change the permissions on only those files that needs it:
find scripts -type f -name '*.sh' ! -perm -u+x -exec chmod u+x +
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The safest way to do this is to let find
execute chmod
directly, and also to be more careful in the selection of the files:
find scripts -type f -name '*.sh' -exec chmod u+x +
This will find all regular files in or below the scripts
directory that have names that end with .sh
and will run chmod u+x
on as many of these as possible at once. It will handle possibly weird filenames without issues.
To change the permissions on only those files that needs it:
find scripts -type f -name '*.sh' ! -perm -u+x -exec chmod u+x +
The safest way to do this is to let find
execute chmod
directly, and also to be more careful in the selection of the files:
find scripts -type f -name '*.sh' -exec chmod u+x +
This will find all regular files in or below the scripts
directory that have names that end with .sh
and will run chmod u+x
on as many of these as possible at once. It will handle possibly weird filenames without issues.
To change the permissions on only those files that needs it:
find scripts -type f -name '*.sh' ! -perm -u+x -exec chmod u+x +
answered Apr 27 at 6:48
Kusalananda
102k13199315
102k13199315
add a comment |Â
add a comment |Â
Your belief is not accurate. What happens when you run it that makes you think it's doing that? Are there any unusual file names or file permissions?
â Michael Homer
Apr 27 at 4:55
nah no unusual filenames...wouldn't the xargs command be different than the first one? if one command, works the other shouldn't..
â Alexander Mills
Apr 27 at 5:02
Why do you think that those commands canâÂÂt both work? (Ignoring file names with whitespace etc.)
â Stephen Kitt
Apr 27 at 5:45
Uhh with the first one, since the find command returns newline separate results, I wasn't under the impression that
chmod u+x
(or any similar command) can handle thatâ Alexander Mills
Apr 27 at 6:53
1
Oh,
chmod
doesnâÂÂt need to handle newlines in the result of a command substitution: the shell parses everything (and it removes newlines from the output).â Stephen Kitt
Apr 30 at 9:02