Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #!/bin/bash
  2. LIMIT=500000
  3. NO=0
  4. #Get the number of files, that has `*.pcap` in its name, with last modified time 5 days ago
  5.  
  6. NUMBER=$(find /mnt/md0/capture/DCN/ -maxdepth 1 -name "*.pcap" |wc -l)
  7. if [[ $NUMBER -gt $LIMIT ]] #if number greater than limit
  8. then
  9. del=$(($NUMBER-$LIMIT))
  10. if [ "$del" -lt "$NO" ]
  11. then
  12. del=$(($del*-1))
  13. fi
  14. echo $del
  15. FILES=$(
  16. find /mnt/md0/capture/DCN/ -maxdepth 1 -type f -name "*.pcap" -print0 |
  17. xargs -0 ls -lt |
  18. tail -$del |
  19. awk '{print $8}'
  20. )
  21. rm -f ${FILES[@]}
  22. #delete the originals
  23.  
  24. fi
  25.  
  26. find /mnt/md0/capture/DCN/ -maxdepth 1 -type f -name "*.pcap" -print0 |
  27. xargs -0 ls -lt | tail -n "$del" | awk '{print $8}'
  28.  
  29. ls -dt /mnt/md0/capture/DCN/*.pcap | tail -n "$del"
  30.  
  31. ls -dt /mnt/md0/capture/DCN/*.pcap | tail -n "$del" | xargs rm
  32.  
  33. ls -dt --quoting-style=shell-always /mnt/md0/capture/DCN/*.pcap |
  34. tail -n "$del" | xargs rm
  35.  
  36. #! /bin/zsh -
  37. keep=5000
  38. rm -f /mnt/md0/capture/DCN/*.pcap(D.om[$((keep+1)),-1])
  39.  
  40. cd /mnt/md0/capture/DCN/ &&
  41. find . -maxdepth 1 -name '*.pcap' -type f -printf '%T@@%p' |
  42. sort -zrn | sed -z "s/[^@]*@//;1,$keep d" | xargs -r0 rm -f
  43.  
  44. cd /mnt/md0/capture/DCN/ &&
  45. find . -maxdepth 1 -name '*.pcap' -type f -printf '%T@@%p' |
  46. tr 'n' 'n' | sort -rn | tail -n "+$(($keep+1))" |
  47. cut -d @ -f2- | tr 'n' 'n' | xargs -r0 rm -f
  48.  
  49. shopt -s dotglob
  50. cd /mnt/md0/capture/DCN/ &&
  51. eval "files=($(ls -dt --quoting-style=shell-always -- *.pcap))" &&
  52. rm -f -- "${files[@]:$keep}"
  53.  
  54. cd /mnt/md0/capture/DCN/ &&
  55. ls -dt ./.pcap ./.*.pcap ./*.pcap | awk -v keep="$keep" '
  56. function process() {
  57. if (++n > keep) {
  58. gsub(/[ tn"\''']/,"\\&", file)
  59. print file
  60. file = ""
  61. }
  62. }
  63. /// {
  64. if (NR > 1) process()
  65. file=$0
  66. next
  67. }
  68. {file = file "n" $0}
  69. END {if (NR > 0) process()}' | xargs rm -f
  70.  
  71. mkdir t && cd t
  72.  
  73. # 50500 files, 500 to delete
  74. touch {000001..050500}
  75.  
  76. limit=50000
  77.  
  78. ls -t|tail -n "+$(($limit + 1))"|xargs rm
  79.  
  80. ls|wc -l
  81. 50000
  82.  
  83. limit=5000
  84. Cnt=0
  85. for line in `ls -t`
  86. do
  87. if [[ $Cnt -gt $limit ]]
  88. then
  89. rm $line
  90. fi
  91. Cnt=`expr $Cnt + 1`
  92. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement