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?
s4g3
November 6, 2007, 8:17am
2
Seems more like a homework to me
Why dont u do a little googling and find it out - its really easy
this will help u in increasing your knowledge
~Sage
aigles
November 6, 2007, 9:02am
4
The work can be done with the commands : ls for test basename mv
s4g3
November 6, 2007, 9:22am
5
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.
porter
November 7, 2007, 3:07am
7
Looks like your homework isn't as trivial as you thought.
You could use sed to split the name on the period.