Re: Listing space of all files in all directories into a file (94 Views)
Reply
Occasional Visitor
panpaliya
Posts: 1
Registered: ‎07-28-2008
Message 1 of 5 (94 Views)

Listing space of all files in all directories into a file

I have set of directories (32 directory) which contains couple of files. I need to check the space of each file and write down in some another file. I can do it manually by just typing the command ls -lrt but want it to do by script/automatically.

E.G in directory - /dnbusr1/gbid/gbid01 have the following files

-rw-r--r-- 1 gbx gbx 227 Feb 12 01:22 error
-rw-r--r-- 1 gbx gbx 0 Feb 12 01:22 sucess
-r--r--r-- 1 gbx gbx 4230 Jun 29 05:58 ph25dh00
-r--r--r-- 1 gbx gbx 2088140800 Jun 29 05:58 ph25dd00
-r--r--r-- 1 gbx gbx 7154 Jun 29 05:58 ph25df00
-r--r--r-- 1 gbx gbx 6004 Jun 29 05:58 ph25df00.eng

So my file will contains file name (error) and it's size (error)
Please use plain text.
Outstanding Contributor
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 2 of 5 (94 Views)

Re: Listing space of all files in all directories into a file

Take a look at the du command.

du -sk /dnbusr1/gbid/gbid01 will give the total for the directory

du -sk /dnbusr1/gbid/gbid01/* will give the size of each of the files (and subdirectories)

That may be what you are looking for.


Pete

Pete
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 5 (94 Views)

Re: Listing space of all files in all directories into a file

Hi:

You could do this:

# cat .report
#!/usr/bin/sh
typeset DIRLIST=$1
typeset DIRINFO=$2
while read DIR
do
ls -l ${DIR}/error | awk '{print $5, $9}'
done < ${DIRLIST} > ${DIRINFO}

...run as:

# ./report ./mydirs ./myoutput

...where the input file ./mydirs is a simple list of the directories you want to examine:

# cat ./mydirs
/home/panpaliya
/dnbusr1/gbid/gbid01
/dnbusr2/gbid/gbid02

...and ./myouput will be as requested.

Regards!

...JRF...
Please use plain text.
Honored Contributor
Rasheed Tamton
Posts: 965
Registered: ‎05-18-2002
Message 4 of 5 (94 Views)

Re: Listing space of all files in all directories into a file

Find might also help you.

find /dnbusr1/gbid/ -type f -exec ll {} \; |awk '{print $9 , $5}' > /var/tmp/dnbusr1.txt

Please use plain text.
Respected Contributor
Deepak Kr
Posts: 424
Registered: ‎07-11-2008
Message 5 of 5 (94 Views)

Re: Listing space of all files in all directories into a file

Hi,

A very simple script ::::

##How to get total file size of all files in each directory under /dnbusr1/gbid

for x in `ll /dnbusr1/gbid |awk '{$NF}'`
do
echo "Total File size of directory /dnbusr1/gbid/$x is following" >> /tmp/spacedetails.file
du -sk /dnbusr1/gbid/$x >> /tmp/spacedetails.file
echo "######################"
done

Then run

cat /tmp/spacedetails.file
"There is always some scope for improvement"
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation