Skip to main content
added 7 characters in body
Source Link
Praveen Kumar BS
  • 5.3k
  • 2
  • 11
  • 16

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type d -daystart -mtime -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type d -daystart -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type d -daystart -mtime -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

Added the missed directory type
Source Link
Praveen Kumar BS
  • 5.3k
  • 2
  • 11
  • 16

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type d -daystart -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type -daystart -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type d -daystart -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

un-indened the sh-bang line; indented the if/then's for better readability
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Below script will work fine for you

   #!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
under_7days=`find . -maxdepth 1 -type -daystart -7 | wc -l`
if [[ $under_7days >= 20 ]]
then
find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
else
echo "Since total directories which created under 7 days is $under_7days"
fi
elif [[ $count <= 20 ]]
then
echo "Number of folders exsists in the path is $count"
fi
#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type -daystart -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consisderconsider only the directories in the current path.

Below script will work fine for you

   #!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
under_7days=`find . -maxdepth 1 -type -daystart -7 | wc -l`
if [[ $under_7days >= 20 ]]
then
find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
else
echo "Since total directories which created under 7 days is $under_7days"
fi
elif [[ $count <= 20 ]]
then
echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consisder only the directories in the current path

Below script will work fine for you

#!/bin/bash
count=`find . -maxdepth 1 -type d | wc -l`
if [[ $count > 20 ]]
then
  under_7days=`find . -maxdepth 1 -type -daystart -7 | wc -l`
  if [[ $under_7days >= 20 ]]
  then
    find . -maxdepth 1 -daystart -mtime +7 -exec rm -rvf {} \;
  else
    echo "Since total directories which created under 7 days is $under_7days"
  fi
elif [[ $count <= 20 ]]
then
  echo "Number of folders exsists in the path is $count"
fi

I have used maxdepth 1 so it will consider only the directories in the current path.

Corrected the code let me know for any corrections
Source Link
Praveen Kumar BS
  • 5.3k
  • 2
  • 11
  • 16
Loading
deleted 4 characters in body
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 318
Loading
Source Link
Praveen Kumar BS
  • 5.3k
  • 2
  • 11
  • 16
Loading