Executing command for each newline separated [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1













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






share|improve this 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 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














up vote
0
down vote

favorite
1













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






share|improve this 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 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












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1






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






share|improve this question












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









share|improve this question










share|improve this question




share|improve this question









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 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
















  • 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















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










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 +





share|improve this answer




























    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 +





    share|improve this answer

























      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 +





      share|improve this answer























        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 +





        share|improve this answer













        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 +






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 27 at 6:48









        Kusalananda

        102k13199315




        102k13199315












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?