bashrc function to create a folder every month and switch XDG_DESKTOP_DIR to it

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











up vote
0
down vote

favorite












I am actively using desktop, so files and folders rapidly accumulate on desktop.



I need a bashrc way that it checks month on the first day then creates a directory with month name, finally sets it desktop.







share|improve this question


























    up vote
    0
    down vote

    favorite












    I am actively using desktop, so files and folders rapidly accumulate on desktop.



    I need a bashrc way that it checks month on the first day then creates a directory with month name, finally sets it desktop.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am actively using desktop, so files and folders rapidly accumulate on desktop.



      I need a bashrc way that it checks month on the first day then creates a directory with month name, finally sets it desktop.







      share|improve this question














      I am actively using desktop, so files and folders rapidly accumulate on desktop.



      I need a bashrc way that it checks month on the first day then creates a directory with month name, finally sets it desktop.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '17 at 20:18









      Jeff Schaller

      32.1k849109




      32.1k849109










      asked Nov 28 '17 at 20:16









      kenn

      276516




      276516




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote













          • you can set up a cronjob, that runs a script of your daily: man crontab

          • in the script you:

            • create a folder for the last month on your desktop: man mkdir and How do I assign last month's date (year and month only - 2016-07) as a variable?

            • you run a find that finds all files that are older than one month. Here's an example of a find that deletes (rm) older files -
              you'll need to adapt it to mv older files into the created directory: Delete files older than X days +






          share|improve this answer



























            up vote
            1
            down vote













            First manually change the config by yourself for this month and run this for the next month.



            change_desktop()
            Desktop/$last_month


            This will create the current month's folder in Desktop and then look for the last month in the config and change it to the current month.



            I don't know how to run this piece automatically using the ~/.bashrc, but you can setup a cron job for the user and let it run every month. Just add this code snippet to a file called change_desktop.sh add the following code :



            #!/bin/sh
            change_desktop()
            Desktop/$last_month
            change_desktop


            Then create a cron job for the current user like this :



            0 0 12 * * sh /home/$USER/change_desktop.sh


            If however you want to do this manually, you can add the first code snippet to the ~/.bashrc and run change_desktop in your terminal and it will do the job for you, as it is already a function in your ~/.bashrc.






            share|improve this answer






















            • Thank you for the answer. Does it require to check if current month's folder exists?
              – kenn
              Nov 29 '17 at 9:37

















            up vote
            1
            down vote













            I have managed to concoct my own script.



            new_desktop="$HOME/Desktop/$(LC_ALL=tr_TR.utf8 date +'%B-%Y')"
            if [ ! -d "$new_desktop" ]; then
            mkdir "$new_desktop"
            xdg-user-dirs-update --set DESKTOP "$new_desktop"
            nautilus -q
            fi


            But I doubt about how reliable it is.






            share|improve this answer






















            • The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
              – TomáÅ¡ PospíÅ¡ek
              Nov 29 '17 at 20:21










            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f407579%2fbashrc-function-to-create-a-folder-every-month-and-switch-xdg-desktop-dir-to-it%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            • you can set up a cronjob, that runs a script of your daily: man crontab

            • in the script you:

              • create a folder for the last month on your desktop: man mkdir and How do I assign last month's date (year and month only - 2016-07) as a variable?

              • you run a find that finds all files that are older than one month. Here's an example of a find that deletes (rm) older files -
                you'll need to adapt it to mv older files into the created directory: Delete files older than X days +






            share|improve this answer
























              up vote
              1
              down vote













              • you can set up a cronjob, that runs a script of your daily: man crontab

              • in the script you:

                • create a folder for the last month on your desktop: man mkdir and How do I assign last month's date (year and month only - 2016-07) as a variable?

                • you run a find that finds all files that are older than one month. Here's an example of a find that deletes (rm) older files -
                  you'll need to adapt it to mv older files into the created directory: Delete files older than X days +






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                • you can set up a cronjob, that runs a script of your daily: man crontab

                • in the script you:

                  • create a folder for the last month on your desktop: man mkdir and How do I assign last month's date (year and month only - 2016-07) as a variable?

                  • you run a find that finds all files that are older than one month. Here's an example of a find that deletes (rm) older files -
                    you'll need to adapt it to mv older files into the created directory: Delete files older than X days +






                share|improve this answer












                • you can set up a cronjob, that runs a script of your daily: man crontab

                • in the script you:

                  • create a folder for the last month on your desktop: man mkdir and How do I assign last month's date (year and month only - 2016-07) as a variable?

                  • you run a find that finds all files that are older than one month. Here's an example of a find that deletes (rm) older files -
                    you'll need to adapt it to mv older files into the created directory: Delete files older than X days +







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 28 '17 at 20:46









                TomáÅ¡ PospíÅ¡ek

                542110




                542110






















                    up vote
                    1
                    down vote













                    First manually change the config by yourself for this month and run this for the next month.



                    change_desktop()
                    Desktop/$last_month


                    This will create the current month's folder in Desktop and then look for the last month in the config and change it to the current month.



                    I don't know how to run this piece automatically using the ~/.bashrc, but you can setup a cron job for the user and let it run every month. Just add this code snippet to a file called change_desktop.sh add the following code :



                    #!/bin/sh
                    change_desktop()
                    Desktop/$last_month
                    change_desktop


                    Then create a cron job for the current user like this :



                    0 0 12 * * sh /home/$USER/change_desktop.sh


                    If however you want to do this manually, you can add the first code snippet to the ~/.bashrc and run change_desktop in your terminal and it will do the job for you, as it is already a function in your ~/.bashrc.






                    share|improve this answer






















                    • Thank you for the answer. Does it require to check if current month's folder exists?
                      – kenn
                      Nov 29 '17 at 9:37














                    up vote
                    1
                    down vote













                    First manually change the config by yourself for this month and run this for the next month.



                    change_desktop()
                    Desktop/$last_month


                    This will create the current month's folder in Desktop and then look for the last month in the config and change it to the current month.



                    I don't know how to run this piece automatically using the ~/.bashrc, but you can setup a cron job for the user and let it run every month. Just add this code snippet to a file called change_desktop.sh add the following code :



                    #!/bin/sh
                    change_desktop()
                    Desktop/$last_month
                    change_desktop


                    Then create a cron job for the current user like this :



                    0 0 12 * * sh /home/$USER/change_desktop.sh


                    If however you want to do this manually, you can add the first code snippet to the ~/.bashrc and run change_desktop in your terminal and it will do the job for you, as it is already a function in your ~/.bashrc.






                    share|improve this answer






















                    • Thank you for the answer. Does it require to check if current month's folder exists?
                      – kenn
                      Nov 29 '17 at 9:37












                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    First manually change the config by yourself for this month and run this for the next month.



                    change_desktop()
                    Desktop/$last_month


                    This will create the current month's folder in Desktop and then look for the last month in the config and change it to the current month.



                    I don't know how to run this piece automatically using the ~/.bashrc, but you can setup a cron job for the user and let it run every month. Just add this code snippet to a file called change_desktop.sh add the following code :



                    #!/bin/sh
                    change_desktop()
                    Desktop/$last_month
                    change_desktop


                    Then create a cron job for the current user like this :



                    0 0 12 * * sh /home/$USER/change_desktop.sh


                    If however you want to do this manually, you can add the first code snippet to the ~/.bashrc and run change_desktop in your terminal and it will do the job for you, as it is already a function in your ~/.bashrc.






                    share|improve this answer














                    First manually change the config by yourself for this month and run this for the next month.



                    change_desktop()
                    Desktop/$last_month


                    This will create the current month's folder in Desktop and then look for the last month in the config and change it to the current month.



                    I don't know how to run this piece automatically using the ~/.bashrc, but you can setup a cron job for the user and let it run every month. Just add this code snippet to a file called change_desktop.sh add the following code :



                    #!/bin/sh
                    change_desktop()
                    Desktop/$last_month
                    change_desktop


                    Then create a cron job for the current user like this :



                    0 0 12 * * sh /home/$USER/change_desktop.sh


                    If however you want to do this manually, you can add the first code snippet to the ~/.bashrc and run change_desktop in your terminal and it will do the job for you, as it is already a function in your ~/.bashrc.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 28 '17 at 22:32

























                    answered Nov 28 '17 at 20:56









                    Hunter.S.Thompson

                    4,53631334




                    4,53631334











                    • Thank you for the answer. Does it require to check if current month's folder exists?
                      – kenn
                      Nov 29 '17 at 9:37
















                    • Thank you for the answer. Does it require to check if current month's folder exists?
                      – kenn
                      Nov 29 '17 at 9:37















                    Thank you for the answer. Does it require to check if current month's folder exists?
                    – kenn
                    Nov 29 '17 at 9:37




                    Thank you for the answer. Does it require to check if current month's folder exists?
                    – kenn
                    Nov 29 '17 at 9:37










                    up vote
                    1
                    down vote













                    I have managed to concoct my own script.



                    new_desktop="$HOME/Desktop/$(LC_ALL=tr_TR.utf8 date +'%B-%Y')"
                    if [ ! -d "$new_desktop" ]; then
                    mkdir "$new_desktop"
                    xdg-user-dirs-update --set DESKTOP "$new_desktop"
                    nautilus -q
                    fi


                    But I doubt about how reliable it is.






                    share|improve this answer






















                    • The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
                      – TomáÅ¡ PospíÅ¡ek
                      Nov 29 '17 at 20:21














                    up vote
                    1
                    down vote













                    I have managed to concoct my own script.



                    new_desktop="$HOME/Desktop/$(LC_ALL=tr_TR.utf8 date +'%B-%Y')"
                    if [ ! -d "$new_desktop" ]; then
                    mkdir "$new_desktop"
                    xdg-user-dirs-update --set DESKTOP "$new_desktop"
                    nautilus -q
                    fi


                    But I doubt about how reliable it is.






                    share|improve this answer






















                    • The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
                      – TomáÅ¡ PospíÅ¡ek
                      Nov 29 '17 at 20:21












                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    I have managed to concoct my own script.



                    new_desktop="$HOME/Desktop/$(LC_ALL=tr_TR.utf8 date +'%B-%Y')"
                    if [ ! -d "$new_desktop" ]; then
                    mkdir "$new_desktop"
                    xdg-user-dirs-update --set DESKTOP "$new_desktop"
                    nautilus -q
                    fi


                    But I doubt about how reliable it is.






                    share|improve this answer














                    I have managed to concoct my own script.



                    new_desktop="$HOME/Desktop/$(LC_ALL=tr_TR.utf8 date +'%B-%Y')"
                    if [ ! -d "$new_desktop" ]; then
                    mkdir "$new_desktop"
                    xdg-user-dirs-update --set DESKTOP "$new_desktop"
                    nautilus -q
                    fi


                    But I doubt about how reliable it is.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 30 '17 at 3:14









                    TomáÅ¡ PospíÅ¡ek

                    542110




                    542110










                    answered Nov 29 '17 at 11:44









                    kenn

                    276516




                    276516











                    • The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
                      – TomáÅ¡ PospíÅ¡ek
                      Nov 29 '17 at 20:21
















                    • The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
                      – TomáÅ¡ PospíÅ¡ek
                      Nov 29 '17 at 20:21















                    The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
                    – TomáÅ¡ PospíÅ¡ek
                    Nov 29 '17 at 20:21




                    The script looks nice to me! I allowed myself to improve it a bit: indented it, corrected the line break, used a variable $new_desktop instead of repeating the same expression over and over...
                    – TomáÅ¡ PospíÅ¡ek
                    Nov 29 '17 at 20:21

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407579%2fbashrc-function-to-create-a-folder-every-month-and-switch-xdg-desktop-dir-to-it%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

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

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay