<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: &amp;quot;delete&amp;quot; shell script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404476#M14495</link>
    <description>Add "set -xv" as the second line in your script and re-run.  That will let you know what the values of the variables in your script are at run-time.</description>
    <pubDate>Wed, 27 Oct 2004 17:24:34 GMT</pubDate>
    <dc:creator>James A. Donovan</dc:creator>
    <dc:date>2004-10-27T17:24:34Z</dc:date>
    <item>
      <title>"delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404470#M14489</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I need a shell script to monitor a directory's size. When there is no more space left on the disk I want to delete some subdirectories. The subdirectories are in the format:&lt;BR /&gt;backup_of_20041011&lt;BR /&gt;backup_of_20041012&lt;BR /&gt;where 20041011 is the date.&lt;BR /&gt;&lt;BR /&gt;The last 10 (newest) subdirectories should not be deleted, only the oldest ones.&lt;BR /&gt;&lt;BR /&gt;Can I easily find such a script, and if so where is a good place to look?&lt;BR /&gt;&lt;BR /&gt;If not, what are the main functions needed to accomplish these tasks? I am new to Bash programming so any comments are welcome.&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Wed, 20 Oct 2004 13:51:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404470#M14489</guid>
      <dc:creator>Jano_1</dc:creator>
      <dc:date>2004-10-20T13:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404471#M14490</link>
      <description>Attaching an example script that selects files based on age. the +mtime option is the critical thing to look at.&lt;BR /&gt;&lt;BR /&gt;This script uses external libraries, but you don't need that.&lt;BR /&gt;&lt;BR /&gt;My script cleans up pdf files but is adaptable.&lt;BR /&gt;&lt;BR /&gt;Better than seeing if the filesystem is full, its a good idea to pick a certain number of days retention and be done with it. Makes the process less complex.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Wed, 20 Oct 2004 14:26:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404471#M14490</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2004-10-20T14:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404472#M14491</link>
      <description>Hi Steven,&lt;BR /&gt;&lt;BR /&gt;It is an impressive script that you attached. However I am looking for something quite simple. I decided to retain 10 directories.&lt;BR /&gt;&lt;BR /&gt;ls -1 list my directories.&lt;BR /&gt;&lt;BR /&gt;How do I put this output in an array so I can delete a directory per element reference? eg. &lt;BR /&gt;list{1)&lt;BR /&gt;list{2}&lt;BR /&gt;...&lt;BR /&gt;list{y}&lt;BR /&gt;&lt;BR /&gt;And y-10=x, which means I should delete&lt;BR /&gt;list{1) to list{x}&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Thu, 21 Oct 2004 12:18:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404472#M14491</guid>
      <dc:creator>Jano_1</dc:creator>
      <dc:date>2004-10-21T12:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404473#M14492</link>
      <description>A 1-liner way of doing this. I'm not sure how you determine which 10 directories to retain so I am going in order - forward and backwards.&lt;BR /&gt;&lt;BR /&gt;from the directory you are working with;&lt;BR /&gt;ls -l | grep '^d' | head -10  -  this will produce a list of the first 10 directories.&lt;BR /&gt;&lt;BR /&gt;ls -l | grep '^d' | tail -10  -  this will producr a list of the last 10 directories.&lt;BR /&gt;&lt;BR /&gt;rm -rf `ls -l | grep '^d' | head -10`  - This will force remove the first 10 directories. You can add additional conditions to this command, such as grep -v. (Notice the backticks with the rm command.)&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Oct 2004 14:25:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404473#M14492</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2004-10-21T14:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404474#M14493</link>
      <description>Hi Rick,&lt;BR /&gt;&lt;BR /&gt;Cool answer- I will try it out.&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Thu, 21 Oct 2004 14:28:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404474#M14493</guid>
      <dc:creator>Jano_1</dc:creator>
      <dc:date>2004-10-21T14:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404475#M14494</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Does anyone know what is wrong with this line in my script:&lt;BR /&gt;        rm -rf `ls -1 $DIR | head -$TODELETE` &amp;amp;&lt;BR /&gt;The line proceeding this one prints the directories to be deleted perfectly, but this line does not remove anything, and also gives no error.&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt;Jano&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;DIR="/mnt/nas/"&lt;BR /&gt;# amount of directories to keep&lt;BR /&gt;TOKEEP=10&lt;BR /&gt;&lt;BR /&gt;TOTAL=0&lt;BR /&gt;# count total directories&lt;BR /&gt;TOTAL=`ls -l $DIR | grep '^d' | wc -l`&lt;BR /&gt;&lt;BR /&gt;echo Total $TOTAL&lt;BR /&gt;echo Tokeep $TOKEEP&lt;BR /&gt;&lt;BR /&gt;#test if TODELETE &amp;gt; 0&lt;BR /&gt;TODELETE=$[TOTAL-TOKEEP]&lt;BR /&gt;echo Todelete $TODELETE&lt;BR /&gt;&lt;BR /&gt;if [ "$TODELETE" -gt 0 ] ; then&lt;BR /&gt;        # something to do so let's continue&lt;BR /&gt;#        ls -1 $DIR | head -$TODELETE&lt;BR /&gt;        rm -rf `ls -1 $DIR | head -$TODELETE` &amp;amp;&lt;BR /&gt;    else &lt;BR /&gt;        # nothing to do so let's stop&lt;BR /&gt;        echo nothing to delete&lt;BR /&gt;fi</description>
      <pubDate>Wed, 27 Oct 2004 09:26:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404475#M14494</guid>
      <dc:creator>Jano_1</dc:creator>
      <dc:date>2004-10-27T09:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404476#M14495</link>
      <description>Add "set -xv" as the second line in your script and re-run.  That will let you know what the values of the variables in your script are at run-time.</description>
      <pubDate>Wed, 27 Oct 2004 17:24:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404476#M14495</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2004-10-27T17:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404477#M14496</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;From the last line of the debug I can see that the script is trying to delete the right directory (&lt;BR /&gt;+ rm -rf backup_of_20041018)&lt;BR /&gt;but it looks as though the path (DIR=/mnt/nas/) got lost somehow.&lt;BR /&gt;&lt;BR /&gt;Here is the output as requested:&lt;BR /&gt;&lt;BR /&gt;DIR="/mnt/nas/"&lt;BR /&gt;+ DIR=/mnt/nas/&lt;BR /&gt;# amount of directories to keep&lt;BR /&gt;TOKEEP=10&lt;BR /&gt;+ TOKEEP=10&lt;BR /&gt;&lt;BR /&gt;TOTAL=0&lt;BR /&gt;+ TOTAL=0&lt;BR /&gt;# count total directories&lt;BR /&gt;TOTAL=`ls -l $DIR | grep '^d' | wc -l`&lt;BR /&gt;ls -l $DIR | grep '^d' | wc -l&lt;BR /&gt;++ ls -l /mnt/nas/&lt;BR /&gt;++ grep '^d'&lt;BR /&gt;++ wc -l&lt;BR /&gt;+ TOTAL=     11&lt;BR /&gt;&lt;BR /&gt;echo Total $TOTAL&lt;BR /&gt;+ echo Total 11&lt;BR /&gt;Total 11&lt;BR /&gt;echo Tokeep $TOKEEP&lt;BR /&gt;+ echo Tokeep 10&lt;BR /&gt;Tokeep 10&lt;BR /&gt;&lt;BR /&gt;#test if TODELETE &amp;gt; 0&lt;BR /&gt;TODELETE=$[TOTAL-TOKEEP]&lt;BR /&gt;+ TODELETE=1&lt;BR /&gt;echo Todelete $TODELETE&lt;BR /&gt;+ echo Todelete 1&lt;BR /&gt;Todelete 1&lt;BR /&gt;&lt;BR /&gt;if [ "$TODELETE" -gt 0 ] ; then&lt;BR /&gt;        # something to do so let's continue&lt;BR /&gt;#        ls -1 $DIR | head -$TODELETE&lt;BR /&gt;        rm -rf `ls -1 $DIR | head -$TODELETE` &amp;amp;&lt;BR /&gt;    else &lt;BR /&gt;        # nothing to do so let's stop&lt;BR /&gt;        echo nothing to delete&lt;BR /&gt;fi&lt;BR /&gt;+ '[' 1 -gt 0 ']'&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;+ exit 0&lt;BR /&gt;[root@server]# ++ head -1&lt;BR /&gt;+ rm -rf backup_of_20041018&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Oct 2004 07:25:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404477#M14496</guid>
      <dc:creator>Jano_1</dc:creator>
      <dc:date>2004-10-28T07:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404478#M14497</link>
      <description>Jano,&lt;BR /&gt;&lt;BR /&gt;The directory part given as argument to the ls command is not included in the output.&lt;BR /&gt;&lt;BR /&gt;If you change this line:&lt;BR /&gt;rm -rf `ls -1 $DIR | head -$TODELETE` &amp;amp;&lt;BR /&gt;&lt;BR /&gt;To:&lt;BR /&gt;ls $DIR | head -$TODELETE |&lt;BR /&gt;while read TARGET&lt;BR /&gt;do&lt;BR /&gt;     rm -rf $DIR/$TARGET&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;But test it first by replacing the "rm -rf" part with "echo" to see that the correct dirs are displayed.&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Oct 2004 07:05:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404478#M14497</guid>
      <dc:creator>Henrik Palmqvist</dc:creator>
      <dc:date>2004-10-29T07:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: "delete" shell script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404479#M14498</link>
      <description>Hi Steven E. Protter &lt;BR /&gt;&lt;BR /&gt;Saw your script, but my need to get the list of the versions in the partition having more disk usage., if we come across the no space left on the device we come across the struggle to increase space.&lt;BR /&gt;&lt;BR /&gt;could you help me to give me some what helpful to me and all..&lt;BR /&gt;&lt;BR /&gt;my requirement: to list versions occupy for a particular package, and how many times a same space contained versions are distributed.&lt;BR /&gt;&lt;BR /&gt;thanks in advance in helping me..&lt;BR /&gt;Regards,&lt;BR /&gt;Shanker G.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Nov 2008 15:26:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/quot-delete-quot-shell-script/m-p/3404479#M14498</guid>
      <dc:creator>shanker_3</dc:creator>
      <dc:date>2008-11-21T15:26:15Z</dc:date>
    </item>
  </channel>
</rss>

