post #1 of 1
Thread Starter 
I need some help to write a special command in the console.

I want to call the size of files in the trash, with some suffix formating (sorry, my English sucks). This code works great :

Code:

du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " $1"B" }'



I added a "B" at the end to write the size in "KB", "MB" and "GB".
However, when the trash is empty, it gives 0 BB, which is odd.

I tried something like the following code, but obviously it doesn't work :

Code:


du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " if $1 > 0 then $1"B" else "0"}'



How can I define the "if then" condition so the code says, for example, 34MB and 0B, and not 34MB and 0BB ?

If I use the following code :

Code:

du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " $1 }'



Then I'll get 34M and 0B, which I don't like. It must be 34MB and 0B.

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply