Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- LIMIT=500000
- NO=0
- #Get the number of files, that has `*.pcap` in its name, with last modified time 5 days ago
- NUMBER=$(find /mnt/md0/capture/DCN/ -maxdepth 1 -name "*.pcap" |wc -l)
- if [[ $NUMBER -gt $LIMIT ]] #if number greater than limit
- then
- del=$(($NUMBER-$LIMIT))
- if [ "$del" -lt "$NO" ]
- then
- del=$(($del*-1))
- fi
- echo $del
- FILES=$(
- find /mnt/md0/capture/DCN/ -maxdepth 1 -type f -name "*.pcap" -print0 |
- xargs -0 ls -lt |
- tail -$del |
- awk '{print $8}'
- )
- rm -f ${FILES[@]}
- #delete the originals
- fi
- find /mnt/md0/capture/DCN/ -maxdepth 1 -type f -name "*.pcap" -print0 |
- xargs -0 ls -lt | tail -n "$del" | awk '{print $8}'
- ls -dt /mnt/md0/capture/DCN/*.pcap | tail -n "$del"
- ls -dt /mnt/md0/capture/DCN/*.pcap | tail -n "$del" | xargs rm
- ls -dt --quoting-style=shell-always /mnt/md0/capture/DCN/*.pcap |
- tail -n "$del" | xargs rm
- #! /bin/zsh -
- keep=5000
- rm -f /mnt/md0/capture/DCN/*.pcap(D.om[$((keep+1)),-1])
- cd /mnt/md0/capture/DCN/ &&
- find . -maxdepth 1 -name '*.pcap' -type f -printf '%T@@%p ' |
- sort -zrn | sed -z "s/[^@]*@//;1,$keep d" | xargs -r0 rm -f
- cd /mnt/md0/capture/DCN/ &&
- find . -maxdepth 1 -name '*.pcap' -type f -printf '%T@@%p ' |
- tr '