How to compare if the size of the directory is more than 500MB in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare if the size of the directory is more than 500MB in unix
# 1  
Old 02-13-2012
How to compare if the size of the directory is more than 500MB in unix

I use du -sk command to find the size of the directory but when i use the result of 'du -sk' into if statement its throwing error.. Could u solve with this..?
# 2  
Old 02-13-2012
what error ?

show your script
# 3  
Old 02-13-2012
My Script is,
Code:
size='du -sh'
$size
size1='30M'
if [ $size -gt $size1 ]
then
  echo "size greater"
else
  echo "size smaller"
fi

its showing

Code:
36M     .
size.sh: line 4: [: too many arguments
size smaller

Error

Last edited by Franklin52; 02-13-2012 at 10:01 AM.. Reason: Please use code tags for data and code samples, thank you
# 4  
Old 02-13-2012
i think du -sh is not correct cmd for that
# 5  
Old 02-13-2012
try this..

Code:
 
size=`du -sh`
size=`echo $size | sed 's/.$//'`
size1='30'
if [ $size -gt $size1 ]
then
echo "size greater"
else
echo "size smaller"
fi

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 02-13-2012
Yep.. Working !! Thank you
# 7  
Old 02-13-2012
@shaal89

you are using -h option, if your directory size goes to 1 to 29 GB, then the above command will fail. Because you are checking it for MB and we are removing the human readable format in the end ( M or G or K )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with Expect script for pulling log files size larger than 500Mb;

I am new at developing EXPECT scripts. I'm trying to create a script that will automatically connect to a several UNIX (sun solaris and HPUX) database server via FTP and pull the sizes of the listener/alert log files from specified server directory on the remote machines. 1. I want the script... (7 Replies)
Discussion started by: mikebantor
7 Replies

2. UNIX for Beginners Questions & Answers

UNIX commands to display the biggest file by size in a directory

Hello guys, Please i need to know the biggest files in my directory let's say$ >du -h | egrep 'M|G|G' 195M ./TMP 3.6M ./TP_DEC2012 146G . But here the result it's giving me the biggest directory in the path. Actually i want to know the biggest file in 146G . Can anyone... (6 Replies)
Discussion started by: gillesi
6 Replies

3. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

4. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

5. UNIX for Dummies Questions & Answers

directory size in unix

hi everyone my q is that i want to know what 's the reason behind the direcotry size in unix like if i do ls -ltr in my home directory it will list all the files and directory .. then the size of directory is either 512 or 1024 .. and every directory is containing files in... (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

6. Red Hat

compare/diff two directory in two different linux/unix machine

Hi, I have two server , one linux and one unix . I want to compare two different directry in them . What command or tool I can use instead of search the dir one by one ??? thank (3 Replies)
Discussion started by: chuikingman
3 Replies

7. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

8. Shell Programming and Scripting

How to compare size of two file which is in one directory

I have two file in a Directory.I want a script which will compare the Size of Two file. Can Anyone Help me on this: linasplg11:/opt/dataout/kk/linasplg11 # cat size -rwxrwxrwx 1 root root 16658 Jan 8 13:58 lina_IP_SIP_1231325621210.xml -rwxr-xr-x 1 root root 16672 Jan 8 14:30... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

9. UNIX for Advanced & Expert Users

largest size directory in unix

I want to find the which directory under a directory occupy the maximum size is there is any command to find please help (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

10. UNIX for Dummies Questions & Answers

How can I get the directory size in Unix?

Hi,everyone, Can I use UNIX command to get a directory size in UNIX ? I am developing a software using C in UNIX. How can I get the directory size? Thanks Harry (1 Reply)
Discussion started by: HarryHong
1 Replies
Login or Register to Ask a Question