How can I create a custom terminal command (to run a script)?












32















I'm a web developer. When I want to start working, always i'm executing some command on terminal. For example:



sudo service apache2 start
sudo service mysql start
sublime


For speed up this process, I create a .sh file which contain these commands.



Now, when I want to start working, I'm just executing this .sh file and all services (mysql, apache2 etc.) starting.



Is it possible to create a custom command for this? For example if I type sudo start-working to terminal, it will execute these commands










share|improve this question





























    32















    I'm a web developer. When I want to start working, always i'm executing some command on terminal. For example:



    sudo service apache2 start
    sudo service mysql start
    sublime


    For speed up this process, I create a .sh file which contain these commands.



    Now, when I want to start working, I'm just executing this .sh file and all services (mysql, apache2 etc.) starting.



    Is it possible to create a custom command for this? For example if I type sudo start-working to terminal, it will execute these commands










    share|improve this question



























      32












      32








      32


      26






      I'm a web developer. When I want to start working, always i'm executing some command on terminal. For example:



      sudo service apache2 start
      sudo service mysql start
      sublime


      For speed up this process, I create a .sh file which contain these commands.



      Now, when I want to start working, I'm just executing this .sh file and all services (mysql, apache2 etc.) starting.



      Is it possible to create a custom command for this? For example if I type sudo start-working to terminal, it will execute these commands










      share|improve this question
















      I'm a web developer. When I want to start working, always i'm executing some command on terminal. For example:



      sudo service apache2 start
      sudo service mysql start
      sublime


      For speed up this process, I create a .sh file which contain these commands.



      Now, when I want to start working, I'm just executing this .sh file and all services (mysql, apache2 etc.) starting.



      Is it possible to create a custom command for this? For example if I type sudo start-working to terminal, it will execute these commands







      command-line






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 21 '14 at 22:47









      Seth

      34.1k26110162




      34.1k26110162










      asked Apr 2 '12 at 20:25









      ErayEray

      95052033




      95052033






















          2 Answers
          2






          active

          oldest

          votes


















          51














          A common way people handle this is to make a bin directory in their home directory: mkdir ~/bin



          Then, you can put your custom scripts in there: mv start-working ~/bin



          Make sure your script is executable: chmod +x ~/bin/start-working



          Add this to the bottom of your ~/.bashrc file (if you're using bash, which you probably are): export PATH=$PATH:~/bin



          Now log back in and out of your terminal and you should be able to simply type start-working, and your script will execute.



          Now that your path is setup, any new scripts you drop into your ~/bin you can just type in the name of.






          share|improve this answer



















          • 12





            +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

            – Meysam
            Sep 2 '12 at 7:35











          • Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

            – Kevin Wyman
            Jan 10 '13 at 15:09






          • 2





            The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

            – geirha
            May 16 '13 at 19:53













          • It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

            – Aaron Flores
            Mar 6 '15 at 23:56



















          12














          I was looking how to create custom commands and I found this question among others. I think what I was looking for was for aliases so I'll give you the way to do this with an alias.



          On your home folder:



          nano .bash_aliases


          And there you can write down your commands in one line:



          alias start-working='sudo service apache2 start; sudo service mysql start; sublime'


          After saving the file reconfigure your bashrc



          . ~/.bashrc


          And check your new alias is loaded



          alias


          That's it, you can start working now by running



          start-working





          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%2f118312%2fhow-can-i-create-a-custom-terminal-command-to-run-a-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            51














            A common way people handle this is to make a bin directory in their home directory: mkdir ~/bin



            Then, you can put your custom scripts in there: mv start-working ~/bin



            Make sure your script is executable: chmod +x ~/bin/start-working



            Add this to the bottom of your ~/.bashrc file (if you're using bash, which you probably are): export PATH=$PATH:~/bin



            Now log back in and out of your terminal and you should be able to simply type start-working, and your script will execute.



            Now that your path is setup, any new scripts you drop into your ~/bin you can just type in the name of.






            share|improve this answer



















            • 12





              +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

              – Meysam
              Sep 2 '12 at 7:35











            • Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

              – Kevin Wyman
              Jan 10 '13 at 15:09






            • 2





              The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

              – geirha
              May 16 '13 at 19:53













            • It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

              – Aaron Flores
              Mar 6 '15 at 23:56
















            51














            A common way people handle this is to make a bin directory in their home directory: mkdir ~/bin



            Then, you can put your custom scripts in there: mv start-working ~/bin



            Make sure your script is executable: chmod +x ~/bin/start-working



            Add this to the bottom of your ~/.bashrc file (if you're using bash, which you probably are): export PATH=$PATH:~/bin



            Now log back in and out of your terminal and you should be able to simply type start-working, and your script will execute.



            Now that your path is setup, any new scripts you drop into your ~/bin you can just type in the name of.






            share|improve this answer



















            • 12





              +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

              – Meysam
              Sep 2 '12 at 7:35











            • Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

              – Kevin Wyman
              Jan 10 '13 at 15:09






            • 2





              The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

              – geirha
              May 16 '13 at 19:53













            • It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

              – Aaron Flores
              Mar 6 '15 at 23:56














            51












            51








            51







            A common way people handle this is to make a bin directory in their home directory: mkdir ~/bin



            Then, you can put your custom scripts in there: mv start-working ~/bin



            Make sure your script is executable: chmod +x ~/bin/start-working



            Add this to the bottom of your ~/.bashrc file (if you're using bash, which you probably are): export PATH=$PATH:~/bin



            Now log back in and out of your terminal and you should be able to simply type start-working, and your script will execute.



            Now that your path is setup, any new scripts you drop into your ~/bin you can just type in the name of.






            share|improve this answer













            A common way people handle this is to make a bin directory in their home directory: mkdir ~/bin



            Then, you can put your custom scripts in there: mv start-working ~/bin



            Make sure your script is executable: chmod +x ~/bin/start-working



            Add this to the bottom of your ~/.bashrc file (if you're using bash, which you probably are): export PATH=$PATH:~/bin



            Now log back in and out of your terminal and you should be able to simply type start-working, and your script will execute.



            Now that your path is setup, any new scripts you drop into your ~/bin you can just type in the name of.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 2 '12 at 20:51









            Joseph OppegaardJoseph Oppegaard

            64465




            64465








            • 12





              +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

              – Meysam
              Sep 2 '12 at 7:35











            • Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

              – Kevin Wyman
              Jan 10 '13 at 15:09






            • 2





              The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

              – geirha
              May 16 '13 at 19:53













            • It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

              – Aaron Flores
              Mar 6 '15 at 23:56














            • 12





              +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

              – Meysam
              Sep 2 '12 at 7:35











            • Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

              – Kevin Wyman
              Jan 10 '13 at 15:09






            • 2





              The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

              – geirha
              May 16 '13 at 19:53













            • It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

              – Aaron Flores
              Mar 6 '15 at 23:56








            12




            12





            +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

            – Meysam
            Sep 2 '12 at 7:35





            +1, and instead of logging out and in, you can simply run the source ~/.bashrc or . ~/.bashrc commands to apply the changes.

            – Meysam
            Sep 2 '12 at 7:35













            Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

            – Kevin Wyman
            Jan 10 '13 at 15:09





            Joe Oppegaard, I find this really useful information as there are completed scripts I have and would like run as a command rather than a script. Is there a way to include all subdirectories that you create in ~/bin so that you don't have to include multiple export lines in .bashrc? I tried export PATH=$PATH:~/bin/* but that didn't return the desired results.

            – Kevin Wyman
            Jan 10 '13 at 15:09




            2




            2





            The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

            – geirha
            May 16 '13 at 19:53







            The default ~/.profile already adds ~/bin to PATH, so appending it in ~/.bashrc in addition will pointlessly add it twice or more.

            – geirha
            May 16 '13 at 19:53















            It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

            – Aaron Flores
            Mar 6 '15 at 23:56





            It worked without me appending anything to .bashrc, so you may be able to skip that as geriha says

            – Aaron Flores
            Mar 6 '15 at 23:56













            12














            I was looking how to create custom commands and I found this question among others. I think what I was looking for was for aliases so I'll give you the way to do this with an alias.



            On your home folder:



            nano .bash_aliases


            And there you can write down your commands in one line:



            alias start-working='sudo service apache2 start; sudo service mysql start; sublime'


            After saving the file reconfigure your bashrc



            . ~/.bashrc


            And check your new alias is loaded



            alias


            That's it, you can start working now by running



            start-working





            share|improve this answer






























              12














              I was looking how to create custom commands and I found this question among others. I think what I was looking for was for aliases so I'll give you the way to do this with an alias.



              On your home folder:



              nano .bash_aliases


              And there you can write down your commands in one line:



              alias start-working='sudo service apache2 start; sudo service mysql start; sublime'


              After saving the file reconfigure your bashrc



              . ~/.bashrc


              And check your new alias is loaded



              alias


              That's it, you can start working now by running



              start-working





              share|improve this answer




























                12












                12








                12







                I was looking how to create custom commands and I found this question among others. I think what I was looking for was for aliases so I'll give you the way to do this with an alias.



                On your home folder:



                nano .bash_aliases


                And there you can write down your commands in one line:



                alias start-working='sudo service apache2 start; sudo service mysql start; sublime'


                After saving the file reconfigure your bashrc



                . ~/.bashrc


                And check your new alias is loaded



                alias


                That's it, you can start working now by running



                start-working





                share|improve this answer















                I was looking how to create custom commands and I found this question among others. I think what I was looking for was for aliases so I'll give you the way to do this with an alias.



                On your home folder:



                nano .bash_aliases


                And there you can write down your commands in one line:



                alias start-working='sudo service apache2 start; sudo service mysql start; sublime'


                After saving the file reconfigure your bashrc



                . ~/.bashrc


                And check your new alias is loaded



                alias


                That's it, you can start working now by running



                start-working






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 21 '14 at 22:49









                Seth

                34.1k26110162




                34.1k26110162










                answered May 16 '13 at 13:04









                rohoroho

                30124




                30124






























                    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%2f118312%2fhow-can-i-create-a-custom-terminal-command-to-run-a-script%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

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                     ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕