I would like to list all the files in ~ whose size is greater than 100 kB but without using the find command. I need to do it with stat.
Asked
Active
Viewed 1,928 times
-3
-
All files where? In one directory or everywhere on your system? What have you tried – Chris Davies Oct 07 '18 at 12:46
1 Answers
1
stat can't list files based on a condition, but you can combine find and stat to get them work together:
find -type f -size +100k -exec stat {} +
or to get specific outout for example files permissions:
find -type f -size +100k -exec stat -c %a {} +
Or write a script which only uses stat:
#!/bin/bash
for file in $HOME/*; do
if [ -f "$file" ] && [[ $(stat -c %s "$file") -ge 100000 ]]; then
echo "$file"
fi
done
Ravexina
- 2,638
- 1
- 19
- 33
-
1Thanks. But if I use find, why don't just use find -type f -size +100k ? – Quidam Ibidem Oct 07 '18 at 08:31
-
1I thought you might want to get your output by
statcommand, otherwisefind -type f -size +100kwould works fine. – Ravexina Oct 07 '18 at 08:33