How to copy files to the timestamp generated directory?












0















Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to copy files from the Documents directory to the new created directory that is unique. This will be in a crontab backing up files from documents and when the backup will kick in, it will create new directory for each backup that is uniquely identified by the directory timestamp. For some reason I cannot get the cp or cpio -mdp.



bkdate="date +%Y_%m_%d_%H_%M_%S"
PATH=/home/user/backup/
bksource="/home/user/Documents/"

mkdir /home/user/backup/"bk$(date +%Y_%m_%d_%H_%M_%S)"
cp $bksource * ls | tail -l | $PATH


I could of went with the ctime but unfortunately it does not work with the directory creation date.



This was my approach but with the latest created directory and not file



find $HOME -type d -daystart ctime 0


If someone could please help me out to copy to that new directory, I would really appreciate it.



Solution:
This is one solution using target. I am open to other ways that could be used for this purpose.



bkdest=/home/user/backup
bksource=/home/user/Documents
target=${bkdest}/bk.$(date +%Y_%m_%d_%H_%M_%S)
mkdir -p $target
cp ${bksource}/* ${target}/









share|improve this question
















bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to copy files from the Documents directory to the new created directory that is unique. This will be in a crontab backing up files from documents and when the backup will kick in, it will create new directory for each backup that is uniquely identified by the directory timestamp. For some reason I cannot get the cp or cpio -mdp.



    bkdate="date +%Y_%m_%d_%H_%M_%S"
    PATH=/home/user/backup/
    bksource="/home/user/Documents/"

    mkdir /home/user/backup/"bk$(date +%Y_%m_%d_%H_%M_%S)"
    cp $bksource * ls | tail -l | $PATH


    I could of went with the ctime but unfortunately it does not work with the directory creation date.



    This was my approach but with the latest created directory and not file



    find $HOME -type d -daystart ctime 0


    If someone could please help me out to copy to that new directory, I would really appreciate it.



    Solution:
    This is one solution using target. I am open to other ways that could be used for this purpose.



    bkdest=/home/user/backup
    bksource=/home/user/Documents
    target=${bkdest}/bk.$(date +%Y_%m_%d_%H_%M_%S)
    mkdir -p $target
    cp ${bksource}/* ${target}/









    share|improve this question
















    bumped to the homepage by Community 4 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to copy files from the Documents directory to the new created directory that is unique. This will be in a crontab backing up files from documents and when the backup will kick in, it will create new directory for each backup that is uniquely identified by the directory timestamp. For some reason I cannot get the cp or cpio -mdp.



      bkdate="date +%Y_%m_%d_%H_%M_%S"
      PATH=/home/user/backup/
      bksource="/home/user/Documents/"

      mkdir /home/user/backup/"bk$(date +%Y_%m_%d_%H_%M_%S)"
      cp $bksource * ls | tail -l | $PATH


      I could of went with the ctime but unfortunately it does not work with the directory creation date.



      This was my approach but with the latest created directory and not file



      find $HOME -type d -daystart ctime 0


      If someone could please help me out to copy to that new directory, I would really appreciate it.



      Solution:
      This is one solution using target. I am open to other ways that could be used for this purpose.



      bkdest=/home/user/backup
      bksource=/home/user/Documents
      target=${bkdest}/bk.$(date +%Y_%m_%d_%H_%M_%S)
      mkdir -p $target
      cp ${bksource}/* ${target}/









      share|improve this question
















      Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to copy files from the Documents directory to the new created directory that is unique. This will be in a crontab backing up files from documents and when the backup will kick in, it will create new directory for each backup that is uniquely identified by the directory timestamp. For some reason I cannot get the cp or cpio -mdp.



      bkdate="date +%Y_%m_%d_%H_%M_%S"
      PATH=/home/user/backup/
      bksource="/home/user/Documents/"

      mkdir /home/user/backup/"bk$(date +%Y_%m_%d_%H_%M_%S)"
      cp $bksource * ls | tail -l | $PATH


      I could of went with the ctime but unfortunately it does not work with the directory creation date.



      This was my approach but with the latest created directory and not file



      find $HOME -type d -daystart ctime 0


      If someone could please help me out to copy to that new directory, I would really appreciate it.



      Solution:
      This is one solution using target. I am open to other ways that could be used for this purpose.



      bkdest=/home/user/backup
      bksource=/home/user/Documents
      target=${bkdest}/bk.$(date +%Y_%m_%d_%H_%M_%S)
      mkdir -p $target
      cp ${bksource}/* ${target}/






      bash shell scripting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 29 '15 at 7:45









      Tejas

      1,83421940




      1,83421940










      asked Jul 29 '15 at 6:14









      DmitriyDmitriy

      11




      11





      bumped to the homepage by Community 4 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 4 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You set the location in a variable named $PATH. This variable has a special meaning as the search path where the shell will look for commands to execute. By setting it to a directory which you created (and which therefore is empty), you just made sure that the shell can't find any command anymore.



          Rename that variable to something else. All will be fine then.






          share|improve this answer
























          • So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

            – Dmitriy
            Jul 29 '15 at 6:31













          • Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

            – Wouter Verhelst
            Jul 29 '15 at 6:36











          • Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

            – Dmitriy
            Jul 29 '15 at 6:39













          • If you could please provide an example of how this should work, I would really appreciate it. Thanks!

            – Dmitriy
            Jul 29 '15 at 6:44











          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%2f218979%2fhow-to-copy-files-to-the-timestamp-generated-directory%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









          0














          You set the location in a variable named $PATH. This variable has a special meaning as the search path where the shell will look for commands to execute. By setting it to a directory which you created (and which therefore is empty), you just made sure that the shell can't find any command anymore.



          Rename that variable to something else. All will be fine then.






          share|improve this answer
























          • So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

            – Dmitriy
            Jul 29 '15 at 6:31













          • Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

            – Wouter Verhelst
            Jul 29 '15 at 6:36











          • Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

            – Dmitriy
            Jul 29 '15 at 6:39













          • If you could please provide an example of how this should work, I would really appreciate it. Thanks!

            – Dmitriy
            Jul 29 '15 at 6:44
















          0














          You set the location in a variable named $PATH. This variable has a special meaning as the search path where the shell will look for commands to execute. By setting it to a directory which you created (and which therefore is empty), you just made sure that the shell can't find any command anymore.



          Rename that variable to something else. All will be fine then.






          share|improve this answer
























          • So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

            – Dmitriy
            Jul 29 '15 at 6:31













          • Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

            – Wouter Verhelst
            Jul 29 '15 at 6:36











          • Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

            – Dmitriy
            Jul 29 '15 at 6:39













          • If you could please provide an example of how this should work, I would really appreciate it. Thanks!

            – Dmitriy
            Jul 29 '15 at 6:44














          0












          0








          0







          You set the location in a variable named $PATH. This variable has a special meaning as the search path where the shell will look for commands to execute. By setting it to a directory which you created (and which therefore is empty), you just made sure that the shell can't find any command anymore.



          Rename that variable to something else. All will be fine then.






          share|improve this answer













          You set the location in a variable named $PATH. This variable has a special meaning as the search path where the shell will look for commands to execute. By setting it to a directory which you created (and which therefore is empty), you just made sure that the shell can't find any command anymore.



          Rename that variable to something else. All will be fine then.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 29 '15 at 6:24









          Wouter VerhelstWouter Verhelst

          7,506833




          7,506833













          • So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

            – Dmitriy
            Jul 29 '15 at 6:31













          • Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

            – Wouter Verhelst
            Jul 29 '15 at 6:36











          • Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

            – Dmitriy
            Jul 29 '15 at 6:39













          • If you could please provide an example of how this should work, I would really appreciate it. Thanks!

            – Dmitriy
            Jul 29 '15 at 6:44



















          • So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

            – Dmitriy
            Jul 29 '15 at 6:31













          • Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

            – Wouter Verhelst
            Jul 29 '15 at 6:36











          • Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

            – Dmitriy
            Jul 29 '15 at 6:39













          • If you could please provide an example of how this should work, I would really appreciate it. Thanks!

            – Dmitriy
            Jul 29 '15 at 6:44

















          So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

          – Dmitriy
          Jul 29 '15 at 6:31







          So do you mean to leave $PATH variable as is and then just copy files "cp $bksource * $PATH" and that will work and copy to that particular created folder that has been created previously? Thanks!

          – Dmitriy
          Jul 29 '15 at 6:31















          Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

          – Wouter Verhelst
          Jul 29 '15 at 6:36





          Nonono. rename the PATH variable to something else. You will still need a variable where you store that. Just don't call it PATH,

          – Wouter Verhelst
          Jul 29 '15 at 6:36













          Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

          – Dmitriy
          Jul 29 '15 at 6:39







          Thanks, I'm still a bit confused, then how is $PATH variable being used? it doesn't know the location to which it is assigned. Where am I calling the path, to the "cp" destination?

          – Dmitriy
          Jul 29 '15 at 6:39















          If you could please provide an example of how this should work, I would really appreciate it. Thanks!

          – Dmitriy
          Jul 29 '15 at 6:44





          If you could please provide an example of how this should work, I would really appreciate it. Thanks!

          – Dmitriy
          Jul 29 '15 at 6:44


















          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%2f218979%2fhow-to-copy-files-to-the-timestamp-generated-directory%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

          Accessing regular linux commands in Huawei's Dopra Linux

          Can't connect RFCOMM socket: Host is down

          Kernel panic - not syncing: Fatal Exception in Interrupt