Use chown -R while excluding one or two filesWhat is the purpose of shopt -s extglobchanging permissions of `nyccrash.txt': Operation not permittedchown recursively changed permissionsComparing two text filesJoin two files keeping the element order of one of themFile Permissions and umaskchmod not working in a non super userSetting www-data and me as the owner?using link command to see how it worksComparing contents of two filescompare two lines and print unmatched words from two files

How to avoid theft of potentially patentable IP when trying to obtain a Ph.D?

Why didn't Britain or any other European power colonise Abyssinia/Ethiopia before 1936?

Is it legal to use cash pulled from a credit card to pay the monthly payment on that credit card?

Pointwise convergence of uniformly continuous functions to zero, but not uniformly

Is it legal for private citizens to "impound" e-scooters?

Why do all my history books divide Chinese history after the Han dynasty?

Can anyone give a concrete example to illustrate what is an uniform prior?

How to kill my goat in Goat Simulator

Use cases for M-0 & C-0?

If Trump gets impeached, how long would Pence be president?

How did Mysterio have these drones?

How can I say in Russian "they cannot make the tournament attractive by itself"?

Is a topological space considered to be a class in set theory?

Send a single HTML email from Thunderbird, overriding the default "plain text" setting

What are the different qualities of the intervals?

Seaborn style plot of pandas dataframe

Why do planes need a roll motion?

Word for showing a small part of something briefly to hint to its existence or beauty without fully uncovering it

Why can't my huge trees be chopped down?

What do you call a flexible diving platform?

If my pay period is split between 2 calendar years, which tax year do I file them in?

Suggestions for protecting jeans from saddle clamp bolt

What is the most efficient way to write 'for' loops in Matlab?

Why is drive/partition number still used?



Use chown -R while excluding one or two files


What is the purpose of shopt -s extglobchanging permissions of `nyccrash.txt': Operation not permittedchown recursively changed permissionsComparing two text filesJoin two files keeping the element order of one of themFile Permissions and umaskchmod not working in a non super userSetting www-data and me as the owner?using link command to see how it worksComparing contents of two filescompare two lines and print unmatched words from two files






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















How can I use chown -R but exclude one or two files?



I periodically need to run



sudo chown -R www-data:www-data *


and



sudo chown -R ubuntu:ubuntu *


But I'd like to exclude one or two files from those commands as to not change the permissions of those excluded files.



How can I exclude file1.php, or both file2.txt and file3.php?










share|improve this question
























  • Could you consider allowing permission change on all files, and then reinstating the permissions for those two files?

    – pierrely
    Jul 20 at 6:04

















4















How can I use chown -R but exclude one or two files?



I periodically need to run



sudo chown -R www-data:www-data *


and



sudo chown -R ubuntu:ubuntu *


But I'd like to exclude one or two files from those commands as to not change the permissions of those excluded files.



How can I exclude file1.php, or both file2.txt and file3.php?










share|improve this question
























  • Could you consider allowing permission change on all files, and then reinstating the permissions for those two files?

    – pierrely
    Jul 20 at 6:04













4












4








4


2






How can I use chown -R but exclude one or two files?



I periodically need to run



sudo chown -R www-data:www-data *


and



sudo chown -R ubuntu:ubuntu *


But I'd like to exclude one or two files from those commands as to not change the permissions of those excluded files.



How can I exclude file1.php, or both file2.txt and file3.php?










share|improve this question
















How can I use chown -R but exclude one or two files?



I periodically need to run



sudo chown -R www-data:www-data *


and



sudo chown -R ubuntu:ubuntu *


But I'd like to exclude one or two files from those commands as to not change the permissions of those excluded files.



How can I exclude file1.php, or both file2.txt and file3.php?







command-line chown






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 17 at 19:09









dessert

28.1k6 gold badges84 silver badges116 bronze badges




28.1k6 gold badges84 silver badges116 bronze badges










asked Jul 17 at 17:25









BlueDogRanchBlueDogRanch

1236 bronze badges




1236 bronze badges












  • Could you consider allowing permission change on all files, and then reinstating the permissions for those two files?

    – pierrely
    Jul 20 at 6:04

















  • Could you consider allowing permission change on all files, and then reinstating the permissions for those two files?

    – pierrely
    Jul 20 at 6:04
















Could you consider allowing permission change on all files, and then reinstating the permissions for those two files?

– pierrely
Jul 20 at 6:04





Could you consider allowing permission change on all files, and then reinstating the permissions for those two files?

– pierrely
Jul 20 at 6:04










1 Answer
1






active

oldest

votes


















7














Set bash’s extglob option with



shopt -s extglob


and use it like that to exclude these files:



sudo chown -R www-data:www-data !(file1.php)
sudo chown -R ubuntu:ubuntu !(file2.txt|file3.php)


This works with files and directories equally, but only in the current directory. If you need to exclude files in subdirectories, combine the above with the globstar option (shopt -s globstar):



sudo chown -R www-data:www-data **/!(file1.php)


This matches every file and directory except the ones called file1.php.



Example run



$ touch 1..3
$ shopt -s extglob
$ echo !(1)
2 3
$ echo !(1|2)
3
$ mkdir a
$ touch a/1..3
$ tree
.
├── 1
├── 2
├── 3
└── a
├── 1
├── 2
└── 3
$ shopt -s globstar
$ echo **/!(1|2)
3 a a/3


Further reading




  • man bash/EXPANSION/Pathname Expansion/Pattern Matching

  • What is the purpose of shopt -s extglob

  • bash-hackers.org: Extended pattern language





share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1159025%2fuse-chown-r-while-excluding-one-or-two-files%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    Set bash’s extglob option with



    shopt -s extglob


    and use it like that to exclude these files:



    sudo chown -R www-data:www-data !(file1.php)
    sudo chown -R ubuntu:ubuntu !(file2.txt|file3.php)


    This works with files and directories equally, but only in the current directory. If you need to exclude files in subdirectories, combine the above with the globstar option (shopt -s globstar):



    sudo chown -R www-data:www-data **/!(file1.php)


    This matches every file and directory except the ones called file1.php.



    Example run



    $ touch 1..3
    $ shopt -s extglob
    $ echo !(1)
    2 3
    $ echo !(1|2)
    3
    $ mkdir a
    $ touch a/1..3
    $ tree
    .
    ├── 1
    ├── 2
    ├── 3
    └── a
    ├── 1
    ├── 2
    └── 3
    $ shopt -s globstar
    $ echo **/!(1|2)
    3 a a/3


    Further reading




    • man bash/EXPANSION/Pathname Expansion/Pattern Matching

    • What is the purpose of shopt -s extglob

    • bash-hackers.org: Extended pattern language





    share|improve this answer





























      7














      Set bash’s extglob option with



      shopt -s extglob


      and use it like that to exclude these files:



      sudo chown -R www-data:www-data !(file1.php)
      sudo chown -R ubuntu:ubuntu !(file2.txt|file3.php)


      This works with files and directories equally, but only in the current directory. If you need to exclude files in subdirectories, combine the above with the globstar option (shopt -s globstar):



      sudo chown -R www-data:www-data **/!(file1.php)


      This matches every file and directory except the ones called file1.php.



      Example run



      $ touch 1..3
      $ shopt -s extglob
      $ echo !(1)
      2 3
      $ echo !(1|2)
      3
      $ mkdir a
      $ touch a/1..3
      $ tree
      .
      ├── 1
      ├── 2
      ├── 3
      └── a
      ├── 1
      ├── 2
      └── 3
      $ shopt -s globstar
      $ echo **/!(1|2)
      3 a a/3


      Further reading




      • man bash/EXPANSION/Pathname Expansion/Pattern Matching

      • What is the purpose of shopt -s extglob

      • bash-hackers.org: Extended pattern language





      share|improve this answer



























        7












        7








        7







        Set bash’s extglob option with



        shopt -s extglob


        and use it like that to exclude these files:



        sudo chown -R www-data:www-data !(file1.php)
        sudo chown -R ubuntu:ubuntu !(file2.txt|file3.php)


        This works with files and directories equally, but only in the current directory. If you need to exclude files in subdirectories, combine the above with the globstar option (shopt -s globstar):



        sudo chown -R www-data:www-data **/!(file1.php)


        This matches every file and directory except the ones called file1.php.



        Example run



        $ touch 1..3
        $ shopt -s extglob
        $ echo !(1)
        2 3
        $ echo !(1|2)
        3
        $ mkdir a
        $ touch a/1..3
        $ tree
        .
        ├── 1
        ├── 2
        ├── 3
        └── a
        ├── 1
        ├── 2
        └── 3
        $ shopt -s globstar
        $ echo **/!(1|2)
        3 a a/3


        Further reading




        • man bash/EXPANSION/Pathname Expansion/Pattern Matching

        • What is the purpose of shopt -s extglob

        • bash-hackers.org: Extended pattern language





        share|improve this answer















        Set bash’s extglob option with



        shopt -s extglob


        and use it like that to exclude these files:



        sudo chown -R www-data:www-data !(file1.php)
        sudo chown -R ubuntu:ubuntu !(file2.txt|file3.php)


        This works with files and directories equally, but only in the current directory. If you need to exclude files in subdirectories, combine the above with the globstar option (shopt -s globstar):



        sudo chown -R www-data:www-data **/!(file1.php)


        This matches every file and directory except the ones called file1.php.



        Example run



        $ touch 1..3
        $ shopt -s extglob
        $ echo !(1)
        2 3
        $ echo !(1|2)
        3
        $ mkdir a
        $ touch a/1..3
        $ tree
        .
        ├── 1
        ├── 2
        ├── 3
        └── a
        ├── 1
        ├── 2
        └── 3
        $ shopt -s globstar
        $ echo **/!(1|2)
        3 a a/3


        Further reading




        • man bash/EXPANSION/Pathname Expansion/Pattern Matching

        • What is the purpose of shopt -s extglob

        • bash-hackers.org: Extended pattern language






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jul 17 at 20:32

























        answered Jul 17 at 17:39









        dessertdessert

        28.1k6 gold badges84 silver badges116 bronze badges




        28.1k6 gold badges84 silver badges116 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1159025%2fuse-chown-r-while-excluding-one-or-two-files%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?