Skip to content

Instantly share code, notes, and snippets.

@rafaelmaeuer
Created July 20, 2023 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelmaeuer/3ccf2f313b42ab089f06067ae040fe36 to your computer and use it in GitHub Desktop.
Save rafaelmaeuer/3ccf2f313b42ab089f06067ae040fe36 to your computer and use it in GitHub Desktop.
# The script receives the limit as an argument.
limit=$1
number_of_files=$(ls ./files | wc -l)
if [ $number_of_files -gt $limit ]
then
# There are more files than the limit
# So we need to remove the older ones.
cd files
ls -t | tail --lines=+$(expr $limit + 1) | xargs -d '\n' rm
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment