Schreibe mir ein bash-script um die ältesten Dateien und Unterordner, innerhalb eines…
- User
Schreibe mir ein bash-script um die ältesten Dateien und Unterordner, innerhalb eines ausgewählten Ordners zu löschen. Das Skript soll mit der jeweils ältesten Datei beginnen und dies so lange wiederholen bis der gewählte Ordner kleiner als 10 GB ist.
- Assistant
You can write a bash script to delete the oldest files and sub-directories within a specified directory. The script should start with the oldest file and continue until the chosen directory is less than 10 GB. Here's an example script to do this:
#!/bin/bash
Set the directory to search
directory="/path/to/directory/to/search"
Get the size of the directory
dir_size=directory | cut -f1)
While the directory is larger than 10 GB
while [ $dir_size -gt 10240 ] do
Find the oldest file or directory in the directory
oldest_file=directory -mindepth 1 -printf '%T@ %p\n' | sort -n | head -1 | cut -f2- -d" ")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.