I run this command to find the biggest files:du -Sh | sort -rh | head -5Then I do -rm rf someFile.Is there a way to automatically delete the files found from the former command?
Find biggest files and delete automatically
command line
If you're using GNU tools (which are standard on linux), you could do something like this:stat --printf '%s\t%n\0' ./* |   sort -z -rn |   head -z -n 5 |   cut  -z -f 2- |  xargs -0 -r echo rm -f --(remove the 'echo' once you've tested it).The stat command prints out the filesize and name of each file in the current directory separated by a tab, and with each record terminated by a NUL (\0) byte.the sort command sorts each NUL-terminated record in reverse numeric order.  The head command lists only the first five such records, then cut removes the file size field from each record.Finally xargs takes that (still NUL-terminated) input and uses it as arguments for echo rm -f.Because this uses NUL as the record (filename) terminator, it copes with filenames that have any valid character in them.If you want a minimum file size, then you could insert awk or something between the stat and the sort.  e.g.stat --printf '%s\t%n\0' ./* |   awk 'BEGIN {ORS = RS = \0 } ; $1 > 25000000' |  sort -z -rn | ...NOTE: GNU awk doesn't have a -z option for NUL-terminated records, but does allow you to set the record separator to whatever you want.  We have to set both the output record separator (ORS) and the input record separator (RS) to NUL.Here's another version that uses find to explicitly limit itself to regular files (i.e. excluding directories, named pipes, sockets, etc) in the specified directory only (-maxdepth 1, no subdirs) which are larger than 25M in size (no need for awk).This version doesn't need stat because GNU find also has a printf feature.  BTW, note the difference in the format string - stat uses %n for the filename, while find uses %p.find . -maxdepth 1 -type f -size +25M -printf '%s\t%p\0' |   sort -z -rn |   head -z -n 5 |   cut  -z -f 2- |  xargs -0 -r echo rm -f --To run it for a different directory, replace the . in the find command.  e.g. find /home/web/ ....shell script version:#!/bin/shfor d in $@ ; do  find $d -maxdepth 1 -type f -size +25M -printf '%s\t%p\0' |     sort -z -rn |     head -z -n 5 |     cut  -z -f 2- |    xargs -0 -r echo rm -f --donesave it as, e.g., delete-five-largest.sh somewhere in your PATH and run it as delete-five-largest.sh /home/web /another/directory /and/yet/anotherThis runs the find ... once for each directory specified on the command line.  This is NOT the same as running find once with multiple path arguments (which would look like find $@ ..., without any for loop in the script).   It deletes the 5 largest files in each directory, while running it without the for loop would delete only the five largest files found while searching all of the directories.  i.e. five per directory vs five total.