How to delete old backups based on a date in file name?how to delete files with specific date patternRemove files older than 5 days in UNIX (date in file name, not timestamp)Remove files older than 5 days in UNIX (date in file name, not timestamp)file deletion using forfilesRemove old files in a directory except files present in an exception fileDelete files older than X daysbash script to identify the files based on current date and file name patternDelete sub-directories with YYYYMMDD in name older than N daysFind and delete folders within directory that are older than x daysDeleting older log fileshow to delete files with specific date patternHow to delete all directories in a directory older than 2 weeks except the latest one that match a file pattern?

Failed to fetch jessie backports repository

Applicability of Single Responsibility Principle

Do the temporary hit points from Reckless Abandon stack if I make multiple attacks on my turn?

How does the UK government determine the size of a mandate?

Unreliable Magic - Is it worth it?

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

What is paid subscription needed for in Mortal Kombat 11?

Do all network devices need to make routing decisions, regardless of communication across networks or within a network?

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Gears on left are inverse to gears on right?

What Brexit proposals are on the table in the indicative votes on the 27th of March 2019?

What does "I’d sit this one out, Cap," imply or mean in the context?

Purchasing a ticket for someone else in another country?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?

How easy is it to start Magic from scratch?

How to check is there any negative term in a large list?

How can a function with a hole (removable discontinuity) equal a function with no hole?

How to draw lines on a tikz-cd diagram

Increase performance creating Mandelbrot set in python

Why not increase contact surface when reentering the atmosphere?

CREATE opcode: what does it really do?

Opposite of a diet

Why escape if the_content isnt?



How to delete old backups based on a date in file name?


how to delete files with specific date patternRemove files older than 5 days in UNIX (date in file name, not timestamp)Remove files older than 5 days in UNIX (date in file name, not timestamp)file deletion using forfilesRemove old files in a directory except files present in an exception fileDelete files older than X daysbash script to identify the files based on current date and file name patternDelete sub-directories with YYYYMMDD in name older than N daysFind and delete folders within directory that are older than x daysDeleting older log fileshow to delete files with specific date patternHow to delete all directories in a directory older than 2 weeks except the latest one that match a file pattern?













5















I have a daily backups named like this:



yyyymmddhhmm.zip // pattern
201503200100.zip // backup from 20. 3. 2015 1:00


I'm trying to create a script that deletes all backups older than 3 days. The script should be also able to delete all other files in the folder not matching the pattern (but there would be a switch for that in the script to disable this).



To determine the file age I don't want to use backups timestamps as other programs also manipulate with the files and it can be tampered.



With the help of: Remove files older than 5 days in UNIX (date in file name, not timestamp)
I got:



#!/bin/bash

DELETE_OTHERS=yes
BACKUPS_PATH=/mnt/!ARCHIVE/!backups/
THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

ls -1 $BACKUPS_PATH????????????.zip |
while read A DATE B FILE
do
[[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
done

if [ $DELETE_OTHERS == "yes" ]; then
rm $BACKUPS_PATH*.* // but I don't know how to not-delete the files matching pattern
fi


But it keeps saying:



rm: missing operand


Where is the problem and how to complete the script?










share|improve this question
























  • Do you actually have a ! at the beginning of your ARCHIVE and backups directory names? If so, why in the world would you want to complicate your life in such a way?

    – terdon♦
    Mar 21 '15 at 17:09











  • Yes I have. I'm using ! to keep the one or two key directories on top of the file listings when there is a lot of other files/folders in that directory and it is sorted by name. I am all ears if there is a better technique for that :)

    – Joudicek Jouda
    Mar 21 '15 at 19:13






  • 1





    I just add aa or similar to the name, for example aabackups. That way, you don't need to escape special characters. It's a matter of personal preference though.

    – terdon♦
    Mar 21 '15 at 20:34















5















I have a daily backups named like this:



yyyymmddhhmm.zip // pattern
201503200100.zip // backup from 20. 3. 2015 1:00


I'm trying to create a script that deletes all backups older than 3 days. The script should be also able to delete all other files in the folder not matching the pattern (but there would be a switch for that in the script to disable this).



To determine the file age I don't want to use backups timestamps as other programs also manipulate with the files and it can be tampered.



With the help of: Remove files older than 5 days in UNIX (date in file name, not timestamp)
I got:



#!/bin/bash

DELETE_OTHERS=yes
BACKUPS_PATH=/mnt/!ARCHIVE/!backups/
THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

ls -1 $BACKUPS_PATH????????????.zip |
while read A DATE B FILE
do
[[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
done

if [ $DELETE_OTHERS == "yes" ]; then
rm $BACKUPS_PATH*.* // but I don't know how to not-delete the files matching pattern
fi


But it keeps saying:



rm: missing operand


Where is the problem and how to complete the script?










share|improve this question
























  • Do you actually have a ! at the beginning of your ARCHIVE and backups directory names? If so, why in the world would you want to complicate your life in such a way?

    – terdon♦
    Mar 21 '15 at 17:09











  • Yes I have. I'm using ! to keep the one or two key directories on top of the file listings when there is a lot of other files/folders in that directory and it is sorted by name. I am all ears if there is a better technique for that :)

    – Joudicek Jouda
    Mar 21 '15 at 19:13






  • 1





    I just add aa or similar to the name, for example aabackups. That way, you don't need to escape special characters. It's a matter of personal preference though.

    – terdon♦
    Mar 21 '15 at 20:34













5












5








5


2






I have a daily backups named like this:



yyyymmddhhmm.zip // pattern
201503200100.zip // backup from 20. 3. 2015 1:00


I'm trying to create a script that deletes all backups older than 3 days. The script should be also able to delete all other files in the folder not matching the pattern (but there would be a switch for that in the script to disable this).



To determine the file age I don't want to use backups timestamps as other programs also manipulate with the files and it can be tampered.



With the help of: Remove files older than 5 days in UNIX (date in file name, not timestamp)
I got:



#!/bin/bash

DELETE_OTHERS=yes
BACKUPS_PATH=/mnt/!ARCHIVE/!backups/
THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

ls -1 $BACKUPS_PATH????????????.zip |
while read A DATE B FILE
do
[[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
done

if [ $DELETE_OTHERS == "yes" ]; then
rm $BACKUPS_PATH*.* // but I don't know how to not-delete the files matching pattern
fi


But it keeps saying:



rm: missing operand


Where is the problem and how to complete the script?










share|improve this question
















I have a daily backups named like this:



yyyymmddhhmm.zip // pattern
201503200100.zip // backup from 20. 3. 2015 1:00


I'm trying to create a script that deletes all backups older than 3 days. The script should be also able to delete all other files in the folder not matching the pattern (but there would be a switch for that in the script to disable this).



To determine the file age I don't want to use backups timestamps as other programs also manipulate with the files and it can be tampered.



With the help of: Remove files older than 5 days in UNIX (date in file name, not timestamp)
I got:



#!/bin/bash

DELETE_OTHERS=yes
BACKUPS_PATH=/mnt/!ARCHIVE/!backups/
THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

ls -1 $BACKUPS_PATH????????????.zip |
while read A DATE B FILE
do
[[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
done

if [ $DELETE_OTHERS == "yes" ]; then
rm $BACKUPS_PATH*.* // but I don't know how to not-delete the files matching pattern
fi


But it keeps saying:



rm: missing operand


Where is the problem and how to complete the script?







bash shell-script scripting file-management






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:36









Community♦

1




1










asked Mar 21 '15 at 15:42









Joudicek JoudaJoudicek Jouda

166126




166126












  • Do you actually have a ! at the beginning of your ARCHIVE and backups directory names? If so, why in the world would you want to complicate your life in such a way?

    – terdon♦
    Mar 21 '15 at 17:09











  • Yes I have. I'm using ! to keep the one or two key directories on top of the file listings when there is a lot of other files/folders in that directory and it is sorted by name. I am all ears if there is a better technique for that :)

    – Joudicek Jouda
    Mar 21 '15 at 19:13






  • 1





    I just add aa or similar to the name, for example aabackups. That way, you don't need to escape special characters. It's a matter of personal preference though.

    – terdon♦
    Mar 21 '15 at 20:34

















  • Do you actually have a ! at the beginning of your ARCHIVE and backups directory names? If so, why in the world would you want to complicate your life in such a way?

    – terdon♦
    Mar 21 '15 at 17:09











  • Yes I have. I'm using ! to keep the one or two key directories on top of the file listings when there is a lot of other files/folders in that directory and it is sorted by name. I am all ears if there is a better technique for that :)

    – Joudicek Jouda
    Mar 21 '15 at 19:13






  • 1





    I just add aa or similar to the name, for example aabackups. That way, you don't need to escape special characters. It's a matter of personal preference though.

    – terdon♦
    Mar 21 '15 at 20:34
















Do you actually have a ! at the beginning of your ARCHIVE and backups directory names? If so, why in the world would you want to complicate your life in such a way?

– terdon♦
Mar 21 '15 at 17:09





Do you actually have a ! at the beginning of your ARCHIVE and backups directory names? If so, why in the world would you want to complicate your life in such a way?

– terdon♦
Mar 21 '15 at 17:09













Yes I have. I'm using ! to keep the one or two key directories on top of the file listings when there is a lot of other files/folders in that directory and it is sorted by name. I am all ears if there is a better technique for that :)

– Joudicek Jouda
Mar 21 '15 at 19:13





Yes I have. I'm using ! to keep the one or two key directories on top of the file listings when there is a lot of other files/folders in that directory and it is sorted by name. I am all ears if there is a better technique for that :)

– Joudicek Jouda
Mar 21 '15 at 19:13




1




1





I just add aa or similar to the name, for example aabackups. That way, you don't need to escape special characters. It's a matter of personal preference though.

– terdon♦
Mar 21 '15 at 20:34





I just add aa or similar to the name, for example aabackups. That way, you don't need to escape special characters. It's a matter of personal preference though.

– terdon♦
Mar 21 '15 at 20:34










3 Answers
3






active

oldest

votes


















6














The first problem in your code is that you are parsing ls. This means it will break very easily, if you have any spaces in your file or directory names for example. You should use shell globbing or find instead.



A bigger problem is that you are not reading the data correctly. Your code:



ls -1 | while read A DATE B FILE


will never populate $FILE. The output of ls -1 is just a list of filenames so, unless those file names contain whitespace, only the first of the 4 variables you give to read will be populated.



Here's a working version of your script:



#!/usr/bin/env bash

DELETE_OTHERS=yes
BACKUPS_PATH=/mnt/!ARCHIVE/!backups
THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

## Find all files in $BACKUPS_PATH. The -type f means only files
## and the -maxdepth 1 ensures that any files in subdirectories are
## not included. Combined with -print0 (separate file names with ),
## IFS= (don't break on whitespace), "-d ''" (records end on '') , it can
## deal with all file names.
find $BACKUPS_PATH -maxdepth 1 -type f -print0 | while IFS= read -d '' -r file
do
## Does this file name match the pattern (13 digits, then .zip)?
if [[ "$(basename "$file")" =~ ^[0-9]12.zip$ ]]
then
## Delete the file if it's older than the $THR
[ "$(basename "$file" .zip)" -le "$THRESHOLD" ] && rm -v -- "$file"
else
## If the file does not match the pattern, delete if
## DELETE_OTHERS is set to "yes"
[ $DELETE_OTHERS == "yes" ] && rm -v -- "$file"
fi
done





share|improve this answer
































    0














    don't you forget the sed line between ls -1 and while read, this line IS important.



    for first question I would suggest: (a awk remplacement I was unable to find a sed equivalent)



    ls -1 $BACKUPS_PATH????????????.zip |
    awk -F. 'printf "%s %sn",$1,$0 ;' |
    while read DATE FILE
    do
    [[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
    done


    provided shell arithmetic are at least 37 bit wise to do the $DATE -le $THRESHOLD testing.






    share|improve this answer

























    • This breaks on whitespace and other strange characters.

      – terdon♦
      Mar 21 '15 at 17:45



















    0














    In FreeBSD use:
    Example: find all files in /usr/home/foobar owned by foobar that are older than 5760 minutes (4 days) and delete them.



    find /usr/home/foobar -user foobar -type f -mmin +5760 -delete





    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%2f191632%2fhow-to-delete-old-backups-based-on-a-date-in-file-name%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      The first problem in your code is that you are parsing ls. This means it will break very easily, if you have any spaces in your file or directory names for example. You should use shell globbing or find instead.



      A bigger problem is that you are not reading the data correctly. Your code:



      ls -1 | while read A DATE B FILE


      will never populate $FILE. The output of ls -1 is just a list of filenames so, unless those file names contain whitespace, only the first of the 4 variables you give to read will be populated.



      Here's a working version of your script:



      #!/usr/bin/env bash

      DELETE_OTHERS=yes
      BACKUPS_PATH=/mnt/!ARCHIVE/!backups
      THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

      ## Find all files in $BACKUPS_PATH. The -type f means only files
      ## and the -maxdepth 1 ensures that any files in subdirectories are
      ## not included. Combined with -print0 (separate file names with ),
      ## IFS= (don't break on whitespace), "-d ''" (records end on '') , it can
      ## deal with all file names.
      find $BACKUPS_PATH -maxdepth 1 -type f -print0 | while IFS= read -d '' -r file
      do
      ## Does this file name match the pattern (13 digits, then .zip)?
      if [[ "$(basename "$file")" =~ ^[0-9]12.zip$ ]]
      then
      ## Delete the file if it's older than the $THR
      [ "$(basename "$file" .zip)" -le "$THRESHOLD" ] && rm -v -- "$file"
      else
      ## If the file does not match the pattern, delete if
      ## DELETE_OTHERS is set to "yes"
      [ $DELETE_OTHERS == "yes" ] && rm -v -- "$file"
      fi
      done





      share|improve this answer





























        6














        The first problem in your code is that you are parsing ls. This means it will break very easily, if you have any spaces in your file or directory names for example. You should use shell globbing or find instead.



        A bigger problem is that you are not reading the data correctly. Your code:



        ls -1 | while read A DATE B FILE


        will never populate $FILE. The output of ls -1 is just a list of filenames so, unless those file names contain whitespace, only the first of the 4 variables you give to read will be populated.



        Here's a working version of your script:



        #!/usr/bin/env bash

        DELETE_OTHERS=yes
        BACKUPS_PATH=/mnt/!ARCHIVE/!backups
        THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

        ## Find all files in $BACKUPS_PATH. The -type f means only files
        ## and the -maxdepth 1 ensures that any files in subdirectories are
        ## not included. Combined with -print0 (separate file names with ),
        ## IFS= (don't break on whitespace), "-d ''" (records end on '') , it can
        ## deal with all file names.
        find $BACKUPS_PATH -maxdepth 1 -type f -print0 | while IFS= read -d '' -r file
        do
        ## Does this file name match the pattern (13 digits, then .zip)?
        if [[ "$(basename "$file")" =~ ^[0-9]12.zip$ ]]
        then
        ## Delete the file if it's older than the $THR
        [ "$(basename "$file" .zip)" -le "$THRESHOLD" ] && rm -v -- "$file"
        else
        ## If the file does not match the pattern, delete if
        ## DELETE_OTHERS is set to "yes"
        [ $DELETE_OTHERS == "yes" ] && rm -v -- "$file"
        fi
        done





        share|improve this answer



























          6












          6








          6







          The first problem in your code is that you are parsing ls. This means it will break very easily, if you have any spaces in your file or directory names for example. You should use shell globbing or find instead.



          A bigger problem is that you are not reading the data correctly. Your code:



          ls -1 | while read A DATE B FILE


          will never populate $FILE. The output of ls -1 is just a list of filenames so, unless those file names contain whitespace, only the first of the 4 variables you give to read will be populated.



          Here's a working version of your script:



          #!/usr/bin/env bash

          DELETE_OTHERS=yes
          BACKUPS_PATH=/mnt/!ARCHIVE/!backups
          THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

          ## Find all files in $BACKUPS_PATH. The -type f means only files
          ## and the -maxdepth 1 ensures that any files in subdirectories are
          ## not included. Combined with -print0 (separate file names with ),
          ## IFS= (don't break on whitespace), "-d ''" (records end on '') , it can
          ## deal with all file names.
          find $BACKUPS_PATH -maxdepth 1 -type f -print0 | while IFS= read -d '' -r file
          do
          ## Does this file name match the pattern (13 digits, then .zip)?
          if [[ "$(basename "$file")" =~ ^[0-9]12.zip$ ]]
          then
          ## Delete the file if it's older than the $THR
          [ "$(basename "$file" .zip)" -le "$THRESHOLD" ] && rm -v -- "$file"
          else
          ## If the file does not match the pattern, delete if
          ## DELETE_OTHERS is set to "yes"
          [ $DELETE_OTHERS == "yes" ] && rm -v -- "$file"
          fi
          done





          share|improve this answer















          The first problem in your code is that you are parsing ls. This means it will break very easily, if you have any spaces in your file or directory names for example. You should use shell globbing or find instead.



          A bigger problem is that you are not reading the data correctly. Your code:



          ls -1 | while read A DATE B FILE


          will never populate $FILE. The output of ls -1 is just a list of filenames so, unless those file names contain whitespace, only the first of the 4 variables you give to read will be populated.



          Here's a working version of your script:



          #!/usr/bin/env bash

          DELETE_OTHERS=yes
          BACKUPS_PATH=/mnt/!ARCHIVE/!backups
          THRESHOLD=$(date -d "3 days ago" +%Y%m%d%H%M)

          ## Find all files in $BACKUPS_PATH. The -type f means only files
          ## and the -maxdepth 1 ensures that any files in subdirectories are
          ## not included. Combined with -print0 (separate file names with ),
          ## IFS= (don't break on whitespace), "-d ''" (records end on '') , it can
          ## deal with all file names.
          find $BACKUPS_PATH -maxdepth 1 -type f -print0 | while IFS= read -d '' -r file
          do
          ## Does this file name match the pattern (13 digits, then .zip)?
          if [[ "$(basename "$file")" =~ ^[0-9]12.zip$ ]]
          then
          ## Delete the file if it's older than the $THR
          [ "$(basename "$file" .zip)" -le "$THRESHOLD" ] && rm -v -- "$file"
          else
          ## If the file does not match the pattern, delete if
          ## DELETE_OTHERS is set to "yes"
          [ $DELETE_OTHERS == "yes" ] && rm -v -- "$file"
          fi
          done






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 21 '15 at 17:47

























          answered Mar 21 '15 at 17:38









          terdon♦terdon

          133k32265444




          133k32265444























              0














              don't you forget the sed line between ls -1 and while read, this line IS important.



              for first question I would suggest: (a awk remplacement I was unable to find a sed equivalent)



              ls -1 $BACKUPS_PATH????????????.zip |
              awk -F. 'printf "%s %sn",$1,$0 ;' |
              while read DATE FILE
              do
              [[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
              done


              provided shell arithmetic are at least 37 bit wise to do the $DATE -le $THRESHOLD testing.






              share|improve this answer

























              • This breaks on whitespace and other strange characters.

                – terdon♦
                Mar 21 '15 at 17:45
















              0














              don't you forget the sed line between ls -1 and while read, this line IS important.



              for first question I would suggest: (a awk remplacement I was unable to find a sed equivalent)



              ls -1 $BACKUPS_PATH????????????.zip |
              awk -F. 'printf "%s %sn",$1,$0 ;' |
              while read DATE FILE
              do
              [[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
              done


              provided shell arithmetic are at least 37 bit wise to do the $DATE -le $THRESHOLD testing.






              share|improve this answer

























              • This breaks on whitespace and other strange characters.

                – terdon♦
                Mar 21 '15 at 17:45














              0












              0








              0







              don't you forget the sed line between ls -1 and while read, this line IS important.



              for first question I would suggest: (a awk remplacement I was unable to find a sed equivalent)



              ls -1 $BACKUPS_PATH????????????.zip |
              awk -F. 'printf "%s %sn",$1,$0 ;' |
              while read DATE FILE
              do
              [[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
              done


              provided shell arithmetic are at least 37 bit wise to do the $DATE -le $THRESHOLD testing.






              share|improve this answer















              don't you forget the sed line between ls -1 and while read, this line IS important.



              for first question I would suggest: (a awk remplacement I was unable to find a sed equivalent)



              ls -1 $BACKUPS_PATH????????????.zip |
              awk -F. 'printf "%s %sn",$1,$0 ;' |
              while read DATE FILE
              do
              [[ $DATE -le $THRESHOLD ]] && rm -v $BACKUPS_PATH$FILE
              done


              provided shell arithmetic are at least 37 bit wise to do the $DATE -le $THRESHOLD testing.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 21 '15 at 16:57

























              answered Mar 21 '15 at 16:50









              ArchemarArchemar

              20.4k93973




              20.4k93973












              • This breaks on whitespace and other strange characters.

                – terdon♦
                Mar 21 '15 at 17:45


















              • This breaks on whitespace and other strange characters.

                – terdon♦
                Mar 21 '15 at 17:45

















              This breaks on whitespace and other strange characters.

              – terdon♦
              Mar 21 '15 at 17:45






              This breaks on whitespace and other strange characters.

              – terdon♦
              Mar 21 '15 at 17:45












              0














              In FreeBSD use:
              Example: find all files in /usr/home/foobar owned by foobar that are older than 5760 minutes (4 days) and delete them.



              find /usr/home/foobar -user foobar -type f -mmin +5760 -delete





              share|improve this answer



























                0














                In FreeBSD use:
                Example: find all files in /usr/home/foobar owned by foobar that are older than 5760 minutes (4 days) and delete them.



                find /usr/home/foobar -user foobar -type f -mmin +5760 -delete





                share|improve this answer

























                  0












                  0








                  0







                  In FreeBSD use:
                  Example: find all files in /usr/home/foobar owned by foobar that are older than 5760 minutes (4 days) and delete them.



                  find /usr/home/foobar -user foobar -type f -mmin +5760 -delete





                  share|improve this answer













                  In FreeBSD use:
                  Example: find all files in /usr/home/foobar owned by foobar that are older than 5760 minutes (4 days) and delete them.



                  find /usr/home/foobar -user foobar -type f -mmin +5760 -delete






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 16:40









                  Santiago StaviskiSantiago Staviski

                  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%2f191632%2fhow-to-delete-old-backups-based-on-a-date-in-file-name%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







                      -bash, file-management, scripting, shell-script

                      Popular posts from this blog

                      2017 IndyCar Series Contents Series news Teams and drivers Schedule Season summary Footnotes References External links Navigation menu"INDYCAR: Initial 2018 bodywork concepts unveiled"the original"IndyCar confirms switch to Performance Friction brakes in 2017""AJ Foyt Racing will switch to Chevy"the original"Carlos Munoz, Conor Daly will drive for AJ Foyt Racing""Zach Veach's Indy 500 Debut Confirmed with Foyt""No mass exodus from Honda after Ganassi switch""Ex-F1 driver Sato joins Andretti Autosport for 2017 IndyCar season""IndyCar's Ryan Hunter-Reay, sponsor DHL paired through 2020""hhgregg and Andretti Autosport announce partnership for key races in 2016""INDYCAR: Rossi re-signs with Andretti"the original"McLaren Formula 1 - Fernando Alonso to race at Indy 500 with McLaren, Honda and Andretti Autosport""Shank will finally take part in Indy 500 with Harvey, Andretti | MotorSportsTalk""Andretti adds Jack Harvey to Indy 500 field""Ganassi switches to Honda power for 2017""INDYCAR: Chilton returns to Ganassi"the original"IndyCar silly season: Who's going where in 2017?""INDYCAR: Kanaan, NTT Data return to Ganassi"the original"Kimball to remain at Ganassi for 2017""Coyne confirms Bourdais for 2017 IndyCar season""Davison to sub for Bourdais in Indy 500"the original"Gutierrez confirmed for Detroit IndyCar debut""Gutierrez returns with Coyne for rest of 2017 season""Vautier to drive for Coyne at Texas"the original"INDYCAR: Coyne confirms Jones for 2017"the original"Pippa Mann returns to Coyne for Indy 500""Karam, Dreyer & Reinbold teaming up again for Indianapolis 500""Pigot to return to Ed Carpenter Racing""Hildebrand confirmed as full-time Ed Carpenter driver""Veach to replace injured Hildebrand at Barber"the originalNew Team Harding Racing Enters Chaves for 101st Indianapolis 500"Juncos Racing Announces Entry in 101st Running of the Indianapolis 500 :: Juncos Racing""Juncos confirms Pigot for Indy 500""Saavedra confirmed in Juncos' second 500 entry"the original"Lazier confirms Indy 500 run after son's USF2000 debut"the original"Claman DeMelo to race for RLLR at Sonoma"the original"Rahal signs Servia and ace engineer for 2017""IndyCar: Aleshin returns with Schmidt"the original"Aleshin replaced by Saavedra for Toronto""Jack Harvey will pilot SPM No. 7 car at Watkins Glen, Sonoma""Jay Howard confirmed in Tony Stewart's supported SPM Indy entry""INDYCAR: Newgarden to wave the flag at Penske"the original"Pagenaud opts for No. 1 in 2017"the original"Penske confirms Newgarden for 2017""Montoya to stay with Team Penske in 2017""Target leaving IndyCar after 27 seasons with Chip Ganassi""Cavin: IndyCar could see complete driver/team shakeup in 2017""End of the road for KV Racing?""KV Racing confirms closure, equipment sold to Juncos""Juncos confirms IndyCar Series entry"the original"Juncos readies IndyCar program, aims for '17 500"the original"Harding Racing to add Texas, Pocono to schedule"the original"Sato signs with Andretti Autosport for 2017""INDYCAR: Aleshin in Doubt at SPM"the original"Long Beach notebook: JR Hildebrand breaks hand""Hildebrand cleared to return at Phoenix"the original"Bourdais to undergo surgery on multiple fractures""Aleshin loses Schmidt Peterson IndyCar ride""Saavedra in at SPM for Pocono, Gateway"the original"Bourdais to make return at Gateway"the original"The IndyCar Grand Prix no longer is sponsored by Angie's List""2017 IndyCar Series rulebook""2017 Verizon IndyCar Series Official Rulebook"Official websiteeeeee

                      Can I redirect output to a log file and background a process at the same time?2019 Community Moderator ElectionUnable to write to file in shell script when running command in backgroundredirect and log script outputhow to properly log the output of a console program that frequently updates “parts” of the screen, resulting in a messy log file?How can I redirect the output of a child process?grep script - output lines at the same time into echoHow to run process in background and get its pid to create log file nameHow to redirect output to a log from expect commandHow to clear a redirect log file content in shell?Log background jobs started in all the manually started shells?Why do `jobs` and `dirs` run in command subsitution, process substitution, pipeline, and background jobs output the same as in original shell?How to redirect output to file to STDOUT?

                      Word for a person who has no opinion about whether god existsWord for having a definite opinion while simultaneously withholding judgment?What's the opposite of “newcomer? Is ”veteran" OK?What do you call an “atheist” who might believe in an afterlife?What's a word for someone who wants to voice opinions but not have them challenged?Word for someone who dismisses contrary opinions as irrational?Somone who thinks they are overly special/out of the ordinaryIs there a word, phrase or idiom for “a person who is incapable of thinking about the future”?The belief that a god is human-likeA word for a non-famous person/thing you have heard a lot aboutAdjective for a person who enjoys taking care of their appearance