Skip to content

Instantly share code, notes, and snippets.

@bashizip
Last active August 7, 2025 22:12
Show Gist options
  • Select an option

  • Save bashizip/08cb741269dc272d891d47f250717af0 to your computer and use it in GitHub Desktop.

Select an option

Save bashizip/08cb741269dc272d891d47f250717af0 to your computer and use it in GitHub Desktop.
clean video download directory on linux by deleting all videos older that a number of days.
#!/bin/bash
# Check if the user provided the number of days
if [ -z "$1" ]; then
echo "Usage: $0 <days> [directory]"
echo "Example: $0 5 /path/to/videos"
exit 1
fi
# Get number of days from the first argument
DAYS="$1"
# Get directory from the second argument or use current directory
TARGET_DIR="${2:-.}"
# Delete .mkv and .mp4 files older than specified number of days
find "$TARGET_DIR" -type f \( -iname "*.mkv" -o -iname "*.mp4" \) -mtime +$DAYS -exec rm -f {} \;
echo "Deleted .mkv and .mp4 files older than $DAYS days from $TARGET_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment