Daten im Terminal nach Erstellungsdatum löschen

G

globesessions

Mitglied
Thread Starter
Dabei seit
07.06.2020
Beiträge
45
Reaktionspunkte
3
Hallo,

Ich würde gerne alle Daten von einem Bestimmten Erstellungsdatum löschen.
Im Finder habe ich versucht danach zu suchen, aber da findet er scheinbar nicht alles - durch eine fehlinstalltion kommt jetzt nämlich immer ein Fehlermeldung dass die installierte app nicht funktioniert. Obwohl ich schon wie gesagt im Finder schon versucht habe alle Dateien von dem tag der Installation zu löschen, dürften da immer noch welche versteckt sein.

daher hätte ich es jetzt gerne im Terminal versucht.
aber keinen Befehl für löschen nach Datum gefunden ?

würde das so gehen, oder hat jemand eine Idee bevor ich versehentlich meine ganze HD lösche...

rm * 20230603

?
 
Es gibt da auch keinen direkten Befehl für.
Das koppelt man meist mit find und dessen exec Option.
 
Hast du bei der Findersuche auch versteckte und Systemdateien eingeschlossen?
 
Ich hatte da mal ein Script geschrieben heisst "delete older than" Da kannst Du ein Datum eingeben und einen Pfad dann wird alles was älter als das Datum ist gelöscht. Vielleicht kannst Du das auf Deine Bedürfnisse anpassen. Natürlich wird jegliche Haftung auf Daten und Folgeschäden ausgeschlossen.
AppleScript:
property modDate : ""
activate
deletIt(choose folder multiple selections allowed yes)
on open (var)
    deletIt(var)
end open

on deletIt(var)
    set posPath to POSIX path of item 1 of var
    repeat
        try
            set modDate to text returned of (display dialog "Delete older then how many days?" default answer modDate with title posPath with icon 1) as number
            if modDate < 1 then error
            exit repeat
        on error number ernmb
            if ernmb = -128 then error number -128
            display alert "Value has to be a number greater then 0" as critical
        end try
    end repeat
    set {dateVar, endlist, amount} to {current date, "", 45}
    repeat with x in var
        tell application "Finder"
            try
                set {fiList, pathName} to {(name of files of entire contents of folder x whose modification date is less than dateVar - modDate * days), name of container of x}
            on error erstrg number ernmb
                display alert erstrg message ernmb as critical
                return
            end try
        end tell
    end repeat
    repeat with y in fiList
        if (count paragraphs of endlist) ≤ amount then
            set endlist to endlist & "🚫 " & y & return
        else
            set endlist to endlist & "🚫 and " & (count item of fiList) - amount & " more...‼️"
            exit repeat
        end if
    end repeat
    display alert "Move files in " & quoted form of pathName & " to the trash?" message endlist buttons {"Cancel", "Trash"} cancel button "Cancel" default button "Trash" as critical
    repeat with x in var
        tell application "Finder"
            try
                delete (files of entire contents of folder x whose modification date is less than dateVar - modDate * days)
            on error number ernmb
                display alert ernmb as critical
            end try
        end tell
    end repeat
end deletIt
 
  • Gefällt mir
Reaktionen: globesessions
Zurück
Oben Unten