Monday, April 29, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1234  / 2 Years ago, tue, march 15, 2022, 1:33:14

In a partition I have several files and folders, and I can list all those file sizes with du like this:



du -h


But how can I list all the files which are beyond a specific disk space size like 5MB?


More From » command-line

 Answers
7

Here is a straight-forward solution in bash, which analyzes the size of both files and folders:



#!/bin/bash

folder="$1"
limit="$2"

IFS=$'
'
for item in `find "$folder"`; do
size=$(du -s "$item" | cut -f1)
if [ $size -gt $limit ]; then
echo $item
fi
done


first param is the target folder to examine

second param is the limit in kilobytes, where 1K=1024 bytes.


[#33495] Wednesday, March 16, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ncharm

Total Points: 255
Total Questions: 105
Total Answers: 118

Location: Virgin Islands (U.S.)
Member since Sat, May 6, 2023
1 Year ago
ncharm questions
;