find file size

My Question is
-----------------
Assume you've a directory (i.e /home/test/) which contains n number of files,
rename all the files which has byte count more than zero (0) with .bak extension.
Write shell script to achieve this output,
execute the same without using". / " in front of program name.

Could someone help me?

Seems more like a homework to me :slight_smile:
Why dont u do a little googling and find it out - its really easy

this will help u in increasing your knowledge

~Sage

i could not find it

The work can be done with the commands : ls for test basename mv

Here is a very simple version of the script

for i in `ls -l /home/test/*`
do
if [ -s $i ]
then
mv $i $i.bak
else
continue
fi
done

~Sage

hi,
When i run the code given by you it renames all files irrespective of .bak extension like

before:
student.txt

after code is run
--------------------
student.txt.bak

this is same for all other files including .bak file
i.e if a file exists with name tst.bak
after the code is run it is made as tst.bak.bak.

Looks like your homework isn't as trivial as you thought.

You could use sed to split the name on the period.