22 lines
507 B
Fish
Executable File
22 lines
507 B
Fish
Executable File
#!/usr/bin/env fish
|
|
# $argv[1] = directory you want to scan
|
|
# $argv[2] = minimum amount of files you want to keep
|
|
|
|
set files (count (./golf $argv[1]))
|
|
|
|
if test $files -gt $argv[2]
|
|
set fileList (./golf $argv[1])
|
|
set oldestDate (stat -c %W "$argv[1]/$fileList[1]")
|
|
set fileIndex = 1
|
|
|
|
for i in (seq $files)
|
|
set dateCreated (stat -c %W "$argv[1]/$fileList[$i]")
|
|
if test $dateCreated -gt $oldestDate
|
|
set oldestDate $dateCreated
|
|
set fileIndex $i
|
|
end
|
|
end
|
|
|
|
rm "$argv[1]/$fileList[$fileIndex]"
|
|
end
|