How can I exclude files by default with rsync?

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












12















How can I exclude files by default with rsync? Here is how my normal rsync syntax starts out:



rsync --exclude ".ht*" --exclude "error_log" --exclude ".DS*" --exclude "old" ...


I've seen a lot of mention of configuring the /etc/rsyncd.conf file, but maybe that's more for the daemon than the rsync command.



Is it possible to have some default excludes for rsync when called from the command line like in my default syntax above?










share|improve this question


























    12















    How can I exclude files by default with rsync? Here is how my normal rsync syntax starts out:



    rsync --exclude ".ht*" --exclude "error_log" --exclude ".DS*" --exclude "old" ...


    I've seen a lot of mention of configuring the /etc/rsyncd.conf file, but maybe that's more for the daemon than the rsync command.



    Is it possible to have some default excludes for rsync when called from the command line like in my default syntax above?










    share|improve this question
























      12












      12








      12


      2






      How can I exclude files by default with rsync? Here is how my normal rsync syntax starts out:



      rsync --exclude ".ht*" --exclude "error_log" --exclude ".DS*" --exclude "old" ...


      I've seen a lot of mention of configuring the /etc/rsyncd.conf file, but maybe that's more for the daemon than the rsync command.



      Is it possible to have some default excludes for rsync when called from the command line like in my default syntax above?










      share|improve this question














      How can I exclude files by default with rsync? Here is how my normal rsync syntax starts out:



      rsync --exclude ".ht*" --exclude "error_log" --exclude ".DS*" --exclude "old" ...


      I've seen a lot of mention of configuring the /etc/rsyncd.conf file, but maybe that's more for the daemon than the rsync command.



      Is it possible to have some default excludes for rsync when called from the command line like in my default syntax above?







      linux files configuration rsync






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 29 '11 at 13:05









      cwdcwd

      13.8k52115157




      13.8k52115157




















          4 Answers
          4






          active

          oldest

          votes


















          10














          Add your excludes to a file, then use --exclude-from=/path/to/exclude_file



          e.g.



          # cat rsync.excludes
          .ht*
          error_log
          .DS*
          old
          ...

          # rsync --exclude-from=rsync.excludes





          share|improve this answer




















          • 1





            looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

            – cwd
            Sep 29 '11 at 15:12


















          5














          No, rsync does not have a default configuration file that it will read upon invocation. The best you can do is what @frogstarr78 says and create a text file with patterns, file and directory names to exclude, and then point rsync to it with --exclude-from=filename.






          share|improve this answer




















          • 2





            rsync does not have a default configuration file - that's disappointing

            – cwd
            Sep 29 '11 at 15:06


















          2














          While rsync doesn't let you set default options, you can create a wrapper script and put it higher up in your $PATH than the rsync binary.



          This is is my rsync wrapper which lives in ~/bin/rsync



          #!/bin/sh

          # Set path to the rsync binary
          RSYNC=/usr/bin/rsync

          # Look for these exclude files
          IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)

          EXCLUDE_FROM=""
          for f in $IGNORE_FILES[@]; do
          if [[ -e $f ]]; then
          EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
          fi
          done
          $RSYNC $EXCLUDE_FROM "$@"


          It'll look for ~/.rsyncignore, ./.gitignore, ./.rsyncignore files and, if any of them exist, use them as default --exclude-from arguments.



          Just change the RSYNC and IGNORE_FILES to suit your envrionment and preferences.






          share|improve this answer
































            0














            --exclude "/*" will exclude everything by default. Here is an example:




            rsync -av --include "bin/" --exclude "/*" /source_dir/ /dest_dir/





            share|improve this answer






















              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2funix.stackexchange.com%2fquestions%2f21701%2fhow-can-i-exclude-files-by-default-with-rsync%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              10














              Add your excludes to a file, then use --exclude-from=/path/to/exclude_file



              e.g.



              # cat rsync.excludes
              .ht*
              error_log
              .DS*
              old
              ...

              # rsync --exclude-from=rsync.excludes





              share|improve this answer




















              • 1





                looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

                – cwd
                Sep 29 '11 at 15:12















              10














              Add your excludes to a file, then use --exclude-from=/path/to/exclude_file



              e.g.



              # cat rsync.excludes
              .ht*
              error_log
              .DS*
              old
              ...

              # rsync --exclude-from=rsync.excludes





              share|improve this answer




















              • 1





                looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

                – cwd
                Sep 29 '11 at 15:12













              10












              10








              10







              Add your excludes to a file, then use --exclude-from=/path/to/exclude_file



              e.g.



              # cat rsync.excludes
              .ht*
              error_log
              .DS*
              old
              ...

              # rsync --exclude-from=rsync.excludes





              share|improve this answer















              Add your excludes to a file, then use --exclude-from=/path/to/exclude_file



              e.g.



              # cat rsync.excludes
              .ht*
              error_log
              .DS*
              old
              ...

              # rsync --exclude-from=rsync.excludes






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 27 '12 at 19:51









              gabe.

              6,52093654




              6,52093654










              answered Sep 29 '11 at 13:47









              frogstarr78frogstarr78

              8311611




              8311611







              • 1





                looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

                – cwd
                Sep 29 '11 at 15:12












              • 1





                looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

                – cwd
                Sep 29 '11 at 15:12







              1




              1





              looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

              – cwd
              Sep 29 '11 at 15:12





              looks like the syntax is --exclude-from and not --exclude-file but otherwise this seems to be the ticket. thanks!

              – cwd
              Sep 29 '11 at 15:12













              5














              No, rsync does not have a default configuration file that it will read upon invocation. The best you can do is what @frogstarr78 says and create a text file with patterns, file and directory names to exclude, and then point rsync to it with --exclude-from=filename.






              share|improve this answer




















              • 2





                rsync does not have a default configuration file - that's disappointing

                – cwd
                Sep 29 '11 at 15:06















              5














              No, rsync does not have a default configuration file that it will read upon invocation. The best you can do is what @frogstarr78 says and create a text file with patterns, file and directory names to exclude, and then point rsync to it with --exclude-from=filename.






              share|improve this answer




















              • 2





                rsync does not have a default configuration file - that's disappointing

                – cwd
                Sep 29 '11 at 15:06













              5












              5








              5







              No, rsync does not have a default configuration file that it will read upon invocation. The best you can do is what @frogstarr78 says and create a text file with patterns, file and directory names to exclude, and then point rsync to it with --exclude-from=filename.






              share|improve this answer















              No, rsync does not have a default configuration file that it will read upon invocation. The best you can do is what @frogstarr78 says and create a text file with patterns, file and directory names to exclude, and then point rsync to it with --exclude-from=filename.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Sep 29 '11 at 15:24

























              answered Sep 29 '11 at 14:08









              KusalanandaKusalananda

              130k17247407




              130k17247407







              • 2





                rsync does not have a default configuration file - that's disappointing

                – cwd
                Sep 29 '11 at 15:06












              • 2





                rsync does not have a default configuration file - that's disappointing

                – cwd
                Sep 29 '11 at 15:06







              2




              2





              rsync does not have a default configuration file - that's disappointing

              – cwd
              Sep 29 '11 at 15:06





              rsync does not have a default configuration file - that's disappointing

              – cwd
              Sep 29 '11 at 15:06











              2














              While rsync doesn't let you set default options, you can create a wrapper script and put it higher up in your $PATH than the rsync binary.



              This is is my rsync wrapper which lives in ~/bin/rsync



              #!/bin/sh

              # Set path to the rsync binary
              RSYNC=/usr/bin/rsync

              # Look for these exclude files
              IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)

              EXCLUDE_FROM=""
              for f in $IGNORE_FILES[@]; do
              if [[ -e $f ]]; then
              EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
              fi
              done
              $RSYNC $EXCLUDE_FROM "$@"


              It'll look for ~/.rsyncignore, ./.gitignore, ./.rsyncignore files and, if any of them exist, use them as default --exclude-from arguments.



              Just change the RSYNC and IGNORE_FILES to suit your envrionment and preferences.






              share|improve this answer





























                2














                While rsync doesn't let you set default options, you can create a wrapper script and put it higher up in your $PATH than the rsync binary.



                This is is my rsync wrapper which lives in ~/bin/rsync



                #!/bin/sh

                # Set path to the rsync binary
                RSYNC=/usr/bin/rsync

                # Look for these exclude files
                IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)

                EXCLUDE_FROM=""
                for f in $IGNORE_FILES[@]; do
                if [[ -e $f ]]; then
                EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
                fi
                done
                $RSYNC $EXCLUDE_FROM "$@"


                It'll look for ~/.rsyncignore, ./.gitignore, ./.rsyncignore files and, if any of them exist, use them as default --exclude-from arguments.



                Just change the RSYNC and IGNORE_FILES to suit your envrionment and preferences.






                share|improve this answer



























                  2












                  2








                  2







                  While rsync doesn't let you set default options, you can create a wrapper script and put it higher up in your $PATH than the rsync binary.



                  This is is my rsync wrapper which lives in ~/bin/rsync



                  #!/bin/sh

                  # Set path to the rsync binary
                  RSYNC=/usr/bin/rsync

                  # Look for these exclude files
                  IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)

                  EXCLUDE_FROM=""
                  for f in $IGNORE_FILES[@]; do
                  if [[ -e $f ]]; then
                  EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
                  fi
                  done
                  $RSYNC $EXCLUDE_FROM "$@"


                  It'll look for ~/.rsyncignore, ./.gitignore, ./.rsyncignore files and, if any of them exist, use them as default --exclude-from arguments.



                  Just change the RSYNC and IGNORE_FILES to suit your envrionment and preferences.






                  share|improve this answer















                  While rsync doesn't let you set default options, you can create a wrapper script and put it higher up in your $PATH than the rsync binary.



                  This is is my rsync wrapper which lives in ~/bin/rsync



                  #!/bin/sh

                  # Set path to the rsync binary
                  RSYNC=/usr/bin/rsync

                  # Look for these exclude files
                  IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)

                  EXCLUDE_FROM=""
                  for f in $IGNORE_FILES[@]; do
                  if [[ -e $f ]]; then
                  EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
                  fi
                  done
                  $RSYNC $EXCLUDE_FROM "$@"


                  It'll look for ~/.rsyncignore, ./.gitignore, ./.rsyncignore files and, if any of them exist, use them as default --exclude-from arguments.



                  Just change the RSYNC and IGNORE_FILES to suit your envrionment and preferences.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 16 '13 at 8:26









                  Anthon

                  60.9k17103166




                  60.9k17103166










                  answered May 16 '13 at 8:05









                  scottatronscottatron

                  211




                  211





















                      0














                      --exclude "/*" will exclude everything by default. Here is an example:




                      rsync -av --include "bin/" --exclude "/*" /source_dir/ /dest_dir/





                      share|improve this answer



























                        0














                        --exclude "/*" will exclude everything by default. Here is an example:




                        rsync -av --include "bin/" --exclude "/*" /source_dir/ /dest_dir/





                        share|improve this answer

























                          0












                          0








                          0







                          --exclude "/*" will exclude everything by default. Here is an example:




                          rsync -av --include "bin/" --exclude "/*" /source_dir/ /dest_dir/





                          share|improve this answer













                          --exclude "/*" will exclude everything by default. Here is an example:




                          rsync -av --include "bin/" --exclude "/*" /source_dir/ /dest_dir/






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 28 at 21:03









                          Xinbin DaiXinbin Dai

                          1




                          1



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • 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%2funix.stackexchange.com%2fquestions%2f21701%2fhow-can-i-exclude-files-by-default-with-rsync%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

                              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?