How to check the file size in a dir

Hi all,

I need to check the size of all files in a DIR.Can any one help me out from this?

This is my code:

filenames=`ls -l | cut -c 55-90`
for f in $filenames
do
if [(ls -ltr $f| cut -c 32-40) -gt $1] then
echo $f
done

Output:
file access denied.

*files have read permission alone.

The error message appears unrelated to your script.

As an aside, the first ls is Useless. You might want to use stat instead of ls in order to get easily machine-parsed file sizes.

Also, you seem to have a complex of syntax errors before the "then". You need spaces inside the square brackets, a semicolon before the "then", and a dollar before the parentheses.

for f in *
do
  if [ $(ls -l "$f" | awk '{ print $5 }') -gt $1 ]; then
    echo "$f"
  fi
done

The following is somewhat more succinct:

ls -l | awk -v size=$1 '$5 > size { print substr($0,55) }'

(though I get my file names starting in column 48, not 55). If your awk doesn't understand -v you can see if you have mawk or nawk or gawk instead.

use
ls -l |awk {print $5,"\t",$9}'

The file name might contain whitespace, in which case $9 is only the first word of the file name. Also you are ignoring the requirement to only print file names over a particular size.

#! /usr/bin/bash

for filename in `ls`
  do
  echo $filename `stat -c%s $filename`
done
for filename in *

ls -ltr |grep -v "^d" |awk '{a+=$5} END{print "files size total " a/1000 "KB"}'