10-16-2003
Hi,
I know that it is a very long time since, but I found this thread and I think it might interest you.
Regs David
dirinfo.pl
#----------------------------------------------------------------------------------
#!/opt/perl/bin/perl
use File::Find;
# Determine wether argument is given or not
# -----------------------------------------
if (@ARGV) {
@dirm = @ARGV;
foreach $dirm(@dirm) {
if ($dirm eq "\." ) {
$dirm = `pwd`;
$dirm =~ s/\n//g;
}
$dirm =~ s/\/$//g;
push(@directory, $dirm);
}
}
else {
usage();
}
# -----------------------------------------
# Define global vars and hashes
# -----------------------------------------
%seen = ();
$total = ();
$nr = 0;
$mbnr = 0;
# -----------------------------------------
# Searching starting at your given directory
foreach $directory (@directory) {
finddepth(\&wanted, $directory);
}
# If this is dir is unique, start getting total disk usage inclusive sub-dirs
# -----------------------------------------
sub wanted {
$dir = "$File::Find::dir";
unless ($seen{$dir}++) {
next if ( $dir =~ lost+found );
next if ( $dir eq $directory );
$dm=`du -ks $dir 2>/dev/null`;
($kb, $path) = split /\s+/, $dm ;
$mb = int( $kb / 1024 );
$output{$path} = $mb;
}
}
# -----------------------------------------
# Determine most characters of path and store it in $nr
# -----------------------------------------
@long = keys %output;
foreach $item(@long) {
if ( $nr < length($item)) {
$nr = length($item);
}
}
# -----------------------------------------
# Determine most characters of size and store it in $mbnr
# -----------------------------------------
@long = values %output;
foreach $item(@long) {
if ( $mbnr < length($item)) {
$mbnr = length($item);
}
}
# -----------------------------------------
# Add a space as long as the the current path is smaller then the longest one.
# -----------------------------------------
print "\n\n\n";
while (($key, $value) = each %output) {
$numb = ( $nr - length($key) );
$mbnumb = ( $mbnr - length($value) );
$dd = " Directory $key has";
while ( $numb > 0 ) {
$dd = $dd . " ";
$numb--;
}
while ( $mbnumb > 0 ) {
$dd = $dd . " ";
$mbnumb--;
}
push(@newarray, "$dd $value Mb\n");
}
# -----------------------------------------
# Print total directory size
# -----------------------------------------
foreach $line(sort(@newarray)) {
print $line;
}
print "\n\n";
foreach $directory(@directory) {
$total=`du -ks $directory 2>/dev/null`;
($total_size, $useless) = split /\s+/, $total;
$total_size_mb = int( $total_size / 1024 );
print "Total usage of $directory is $total_size_mb Mb\n";
}
print "\n\n";
# -----------------------------------------
sub usage() {
print "\ndirinfo.pl: Error incorrect usage \n\n";
print "Usage: /usr/local/bin/dirinfo.pl <directory> \n";
print "\t <directory> Is directory start point to check \n\n\n";
exit 1;
}
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
HI,
Can somebody please tell me how many bytes make a KB & MB.
ThANKS.
Rooh.:( (3 Replies)
Discussion started by: rooh
3 Replies
2. UNIX for Dummies Questions & Answers
I need to calcualte the size of a directory by the year the files in that directory were created .
For example the script will sum up, by year, the number of blocks for that directory and its' subdirectories for files created / accessed in that year.
I need a report that would look like... (11 Replies)
Discussion started by: igidttam
11 Replies
3. UNIX for Dummies Questions & Answers
Hi,
After checking all the UNIX threads, I am able to come up with a solution so far. I am working on a shell script where it moves the files to a certain directory. The conditions to check are
1) Check if the file exists in the current directory.
2) Check if the destination directory... (2 Replies)
Discussion started by: madhunk
2 Replies
4. Shell Programming and Scripting
Hi ,
I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level ..
#!/bin/ksh
FNAME='.pdf'
S_PATH=/abc/def/xyz
find $S_PATH -exec ls -lad... (4 Replies)
Discussion started by: Vaddadi
4 Replies
5. Shell Programming and Scripting
Hi I made this code to search in directory for file and size
How can I remodel it to seach in the sub direcotry as well
Thanks
#!/bin/bash
echo -n "Enter: "
read var
if
then
echo "Directory exists: ${var}"
size=`du -hs "${var}"`
echo The size of the current folder is... (4 Replies)
Discussion started by: lio123
4 Replies
6. Shell Programming and Scripting
Suppose i have a word "mail".
I have to search this word in all files inside a directory and it's sub-directories.
It will also search in all hidden directory and sub-directories.
If it finds this word in any file it will list that file.
How can i do this with perl/ruby/awk/sed/bash or... (9 Replies)
Discussion started by: cola
9 Replies
7. Shell Programming and Scripting
Hi Everyone!
Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file.
Any ideas?
Thank you! (1 Reply)
Discussion started by: DanTheMan
1 Replies
8. Shell Programming and Scripting
Hello :
I need some help in writing a ksh script which will find a particular directory in all the file systems in a server and finally report the total size of the direcotry in all the file systems.
Some thing like this..
find /u*/app/oracle -type d -name "product" -prune
and then... (1 Reply)
Discussion started by: Sam1974
1 Replies
9. Programming
Hi,
Can I find size of the file from size of the buffer written?
nbECRITS = fwrite(strstr(data->buffer, ";") + 1, sizeof(char), (data->buffsize) - LEN_NOM_FIC, fic_sortie);
Thank You :) (1 Reply)
Discussion started by: ezee
1 Replies
10. Shell Programming and Scripting
Hi All,
My directory structure is like
Directory1
SubDirectory1
SubDirectory2
SubDirectory3
I have main directories and subdirectories underneath. I want to write a shell script where I will be passing file name as a parameter, Now I want to find all the files in Directory1... (19 Replies)
Discussion started by: John William
19 Replies
sccs-comb(1) User Commands sccs-comb(1)
NAME
sccs-comb, comb - combine SCCS deltas
SYNOPSIS
/usr/ccs/bin/comb [-os] [-csid-list] [-psid] s.filename...
DESCRIPTION
comb generates a shell script (see sh(1)) that you can use to reconstruct the indicated s.files. This script is written to the standard
output.
If a directory name is used in place of the s.filename argument, the comb command applies to all s.files in that directory. Unreadable
s.files produce an error; processing continues with the next file (if any). The use of `-' as the s.filename argument indicates that the
names of files are to be read from the standard input, one s.file per line.
If no options are specified, comb preserves only the most recent (leaf) delta in a branch, and the minimal number of ancestors needed to
preserve the history.
OPTIONS
The following options are supported:
-o For each `get -e' generated, access the reconstructed file at the release of the delta to be created. Otherwise, the recon-
structed file is accessed at the most recent ancestor. The use of -o may decrease the size of the reconstructed s.file. It
may also alter the shape of the delta tree of the original file.
-s Generate scripts to gather statistics, rather than combining deltas. When run, the shell scripts report: the file name,
size (in blocks) after combining, original size (also in blocks), and the percentage size change, computed by the formula:
100 * ( original - combined ) / original
This option can be used to calculate the space that will be saved, before actually doing the combining.
-csid-list Include the indicated list of deltas. All other deltas are omitted. sid-list is a comma-separated list of SCCS delta IDs
(SIDs). To specify a range of deltas, use a `-' separator instead of a comma, between two SIDs in the list.
-pSID The SID of the oldest delta to be preserved.
FILES
s.COMB reconstructed SCCS file
comb????? temporary file
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWsprot |
+-----------------------------+-----------------------------+
SEE ALSO
sccs(1), sccs-admin(1), sccs-cdc(1), sccs-delta(1), sccs-help(1), sccs-prs(1), sccs-prt(1), sccs-rmdel(1), sccs-sccsdiff(1), what(1), sccs-
file(4), attributes(5)
DIAGNOSTICS
Use the SCCS help command for explanations (see sccs-help(1)).
BUGS
comb may rearrange the shape of the tree of deltas. It may not save any space; in fact, it is possible for the reconstructed file to actu-
ally be larger than the original.
SunOS 5.10 1 Nov 1999 sccs-comb(1)