Da sind so viele Varianten welche denn?ast du mal das aus meinem Link in #14 probiert?
Da sind so viele Varianten welche denn?ast du mal das aus meinem Link in #14 probiert?
Ist das deine Erwartungshaltung? Hier im Forum wird eher "Hilfe zur Selbsthilfe" angeboten.Wundert mich, dass da nicht jemand nur copy paste machen kann.
find <PATH_TO_DIR> -maxdepth 1 -type f -printf "%T@ %p\n" | sort -n | head -n -5 | awk {'print $NF'} | xargs -d '\n' rm -f --
head -n -X
angepasst werden.# Erstellen von 20 Dateien
touch file_{1..20}
# Verzeichnis auflisten
ls -lav
----------+ 1 root root 0 Oct 7 00:11 file_1
----------+ 1 root root 0 Oct 7 00:11 file_2
----------+ 1 root root 0 Oct 7 00:11 file_3
----------+ 1 root root 0 Oct 7 00:11 file_4
----------+ 1 root root 0 Oct 7 00:11 file_5
----------+ 1 root root 0 Oct 7 00:11 file_6
----------+ 1 root root 0 Oct 7 00:11 file_7
----------+ 1 root root 0 Oct 7 00:11 file_8
----------+ 1 root root 0 Oct 7 00:11 file_9
----------+ 1 root root 0 Oct 7 00:11 file_10
----------+ 1 root root 0 Oct 7 00:11 file_11
----------+ 1 root root 0 Oct 7 00:11 file_12
----------+ 1 root root 0 Oct 7 00:11 file_13
----------+ 1 root root 0 Oct 7 00:11 file_14
----------+ 1 root root 0 Oct 7 00:11 file_15
----------+ 1 root root 0 Oct 7 00:11 file_16
----------+ 1 root root 0 Oct 7 00:11 file_17
----------+ 1 root root 0 Oct 7 00:11 file_18
----------+ 1 root root 0 Oct 7 00:11 file_19
----------+ 1 root root 0 Oct 7 00:11 file_20
find ./ -maxdepth 1 -type f -printf "%T@ %p\n" | sort -n | head -n -5 | awk {'print $NF'}
# Die Ausgabe sollte wie folgt sein:
./file_1
./file_2
./file_3
./file_4
./file_5
./file_10
./file_6
./file_7
./file_8
./file_9
./file_11
./file_12
./file_13
./file_14
./file_15
xargs -d '\n' rm -f --
hinzu.find ./ -maxdepth 1 -type f -printf "%T@ %p\n" | sort -n | head -n -5 | awk {'print $NF'} | xargs -d '\n' rm -f
# Auflisten des Verzeichnis um die übrigen Dateien anzuzeigen
ls -lav
d---------+ 1 root root 70 Oct 7 00:23 .
d---------+ 1 root root 456 Oct 7 00:10 ..
----------+ 1 root root 0 Oct 7 00:11 file_16
----------+ 1 root root 0 Oct 7 00:11 file_17
----------+ 1 root root 0 Oct 7 00:11 file_18
----------+ 1 root root 0 Oct 7 00:11 file_19
----------+ 1 root root 0 Oct 7 00:11 file_20
touch file_{21..40}
ls -lav
d---------+ 1 root root 350 Oct 7 00:24 .
d---------+ 1 root root 456 Oct 7 00:10 ..
----------+ 1 root root 0 Oct 7 00:11 file_16
----------+ 1 root root 0 Oct 7 00:11 file_17
----------+ 1 root root 0 Oct 7 00:11 file_18
----------+ 1 root root 0 Oct 7 00:11 file_19
----------+ 1 root root 0 Oct 7 00:11 file_20
----------+ 1 root root 0 Oct 7 00:24 file_21
----------+ 1 root root 0 Oct 7 00:24 file_22
----------+ 1 root root 0 Oct 7 00:24 file_23
----------+ 1 root root 0 Oct 7 00:24 file_24
----------+ 1 root root 0 Oct 7 00:24 file_25
----------+ 1 root root 0 Oct 7 00:24 file_26
----------+ 1 root root 0 Oct 7 00:24 file_27
----------+ 1 root root 0 Oct 7 00:24 file_28
----------+ 1 root root 0 Oct 7 00:24 file_29
----------+ 1 root root 0 Oct 7 00:24 file_30
----------+ 1 root root 0 Oct 7 00:24 file_31
----------+ 1 root root 0 Oct 7 00:24 file_32
----------+ 1 root root 0 Oct 7 00:24 file_33
----------+ 1 root root 0 Oct 7 00:24 file_34
----------+ 1 root root 0 Oct 7 00:24 file_35
----------+ 1 root root 0 Oct 7 00:24 file_36
----------+ 1 root root 0 Oct 7 00:24 file_37
----------+ 1 root root 0 Oct 7 00:24 file_38
----------+ 1 root root 0 Oct 7 00:24 file_39
----------+ 1 root root 0 Oct 7 00:24 file_40
# Befehl um die jüngsten 5 Dateien zu behalten
find ./ -maxdepth 1 -type f -printf "%T@ %p\n" | sort -n | head -n -5 | awk {'print $NF'} | xargs -d '\n' rm -f
# Auflisten der übrigen Dateien
ls -lav
d---------+ 1 root root 70 Oct 7 00:27 .
d---------+ 1 root root 456 Oct 7 00:10 ..
----------+ 1 root root 0 Oct 7 00:24 file_36
----------+ 1 root root 0 Oct 7 00:24 file_37
----------+ 1 root root 0 Oct 7 00:24 file_38
----------+ 1 root root 0 Oct 7 00:24 file_39
----------+ 1 root root 0 Oct 7 00:24 file_40
Ist das deine Erwartungshaltung?
Wenn du das Forum hilfreich findest oder uns unterstützen möchtest, dann gib uns doch einfach einen Kaffee aus.
Als Dankeschön schalten wir deinen Account werbefrei.