Results 1 to 3 of 3
Hi all,
I needed help in writing a shell script for the following..
Shell function that takes a valid directory name as an argument and recursively
descends all the subdirectories, ...
- 06-11-2008 #1Just Joined!
- Join Date
- May 2008
- Posts
- 20
needed help in writing a script to find file size?
Hi all,
I needed help in writing a shell script for the following..
Shell function that takes a valid directory name as an argument and recursively
descends all the subdirectories, finds the maximum length of any file in that
hierarchy and writes this maximum value to the standard output.
but this gives me the dir value which has the biggest size....not the file.Code:for i in $*;do x=`ls -lR somedir |awk '{print $5}'|sort -n|tail -1` echo $x
Also if i have subdirs then its not going in search of the sizes for these subdirs?
Could you pls help?
- 06-12-2008 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
try
This script has been tested to work on Ubuntu & OpenSuSE.Code:#!/bin/bash for i in $*; do x=`find $i -type f -ls | sort -k 7 -r -n | awk 'NR==1 {print $7}'` done
- 06-12-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I don't like parsing the ls output like that.
A command named "stat" exists for a reason. This is the way I'd do it:
Code:find /path/to/ -type f | while read file; do stat -c "%s" "$file"; done | sort -g | tail -n1


Reply With Quote