|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Shell script to find size of subdirectories
Hi I have to find size of subdirectory and automate it in CRON. Eg: parent directory name is NVBKP inside it there are several subdirectories I want to get the size of recent two subdirectories. I have tried Code:
ls -ltr diretory path | tail -2 But it is providing only size of the folder not the contents of that folder. For eg if there are 5 subdirectories in NVBKP say Code:
a b c d e then i need complete size of d and e. say complete size of d and e is 25 gb but when i am using Code:
ls -ltr directory path| tail -2 it is giving me only size of folder d and e i.e 256 mb or something but not its contents. Kindly suggest. Last edited by Scrutinizer; 12-26-2012 at 09:32 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
try Code:
ls -lRt and see Last edited by Scrutinizer; 12-26-2012 at 09:32 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
wrong forum, moving thread...
|
|
#4
|
||||
|
||||
|
du
Hi, Try this one, Code:
ls -ltr|awk -v l=2 '/^d/{c++;a[c]=$9;}END{for(i=c-l+1;i<=c;i++){print a[i];}}'|xargs -I '{}' du -sh {}Cheers, Ranga:-) Last edited by rangarasan; 12-27-2012 at 05:01 AM.. Reason: updated |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Hi Thanks for the reply Code:
ls -ltr|tail -2|xargs -I '{}' du -sg {}.Its giving the following result. Code:
du: drwxr-xr-x 3 oranvd dba 256 Dec 16 03:30 20121216: A file or directory in the path name does not exist. du: drwxr-xr-x 3 oranvd dba 256 Dec 23 03:30 20121223: A file or directory in the path name does not exist. Its not giving the desired result these folders has files and the size of the same different but its showing only 256 that is not correct. Last edited by Scrutinizer; 12-27-2012 at 03:21 AM.. Reason: code tags |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
du
Hi, Try this one, Code:
cd dir;
ls -ltr|awk -v l=2 '/^d/{c++;a[c]=$9;}END{for(i=c-l+1;i<=c;i++){print a[i];}}'|xargs -I '{}' du -sh {}You can specify the n number of latest files which you want in variable l. Cheers, Ranga
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thankyou so much Ranga
It worked. Thanks a lot Cheers..... ![]() |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Command for total number of files (and size) across subdirectories? | Beun | UNIX for Dummies Questions & Answers | 9 | 09-01-2011 11:17 AM |
| Shell:Find a word in files in a directory and subdirectories | yeclota | Shell Programming and Scripting | 4 | 08-29-2008 05:05 AM |
| Shell Script to find the tablespace size in oracle. | vighna | Shell Programming and Scripting | 4 | 07-26-2008 10:59 PM |
| shell script to find files by date and size | dadadc | UNIX for Dummies Questions & Answers | 1 | 10-20-2007 05:18 AM |
| Shell script to Find file size | ragsnovel | Shell Programming and Scripting | 1 | 08-10-2007 10:01 AM |
|
|