I am running a UNIX script to get unused files and their sizes from the server. The issue is arising due to the spaces present in the filename/folder names.Due to this the du -k command doesn't work properly.But I need to calculate the size of all files including the ones which have spaces in them.
I have a problem with this part:
for file in `find . -type f -print | cut -c 3- | sed 's/ /#}/g'` //my file name here would be UK#}dump/a.jpg
do
file2=`echo $file | sed 's/#}/ /g'` //my file name here would be UK dump/a.jpg . If I run a du -k command for this filename I will get an error
file3=`echo $file | sed 's/#}/\\\ /g'` // this line is my attempt to change the filename to UK\ dump/a.jpg but it does not happen
size=`du -k $file3 |awk '{print $1}'`
result=`grep -c "$file2" $dbdump`
.........................
done
I have tried the following ways:
1) sed 's/#}/\ /g'`
2) sed 's/#}/\\ /g'`
3) sed 's/#}/\\\ /g'`
4) sed 's/#}/\\\\ /g'`
Some of it works on the command line but doesn't work when I run them as a script.
I cannot use ls -ltr because I dont want the sizes of all files in a folder. I need to get each file in a set of folders, loop through each of them, do some comparison and then write them to a file along with their size.So Could you'll please help me with the same.
Thanks and Regards,
Neil