The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to compare total directory structure and get sizes of all f on two different servers mannam srinivas Shell Programming and Scripting 3 04-07-2008 04:21 AM
Script for checking and reporting file sizes in a directory. marconi Shell Programming and Scripting 1 04-03-2008 08:00 AM
Help on adding file sizes llsmr777 UNIX for Dummies Questions & Answers 1 09-18-2007 02:58 PM
Script for file names/sizes ssmiths001 Shell Programming and Scripting 2 05-09-2006 05:55 PM
syslog log file sizes mscomms UNIX for Advanced & Expert Users 4 06-19-2003 08:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-04-2005
joli joli is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 1
Exclamation compare file sizes

Is there a command that will return the name of the largest file within a directory? If so, can I set the returned filename into a variable?
  #2 (permalink)  
Old 02-04-2005
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 219
Try
LARGEST=`du –s /<path_to_dir>/* | sort –rn | cut –f2 | head –1`
  #3 (permalink)  
Old 02-04-2005
thumsup9 thumsup9 is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 97
try this:

#!/bin/ksh
#say tmp is your directory
cd /tmp
A='find /tmp -type f -print | xargs ls -l | sort -r -n -k 5,5 | head -1'
echo '$A'
  #4 (permalink)  
Old 02-04-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Code:
ls -l | tr -s " " | sort -t" " +4 -n | tail -1 | cut -d" " -f 9
  #5 (permalink)  
Old 02-04-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
'du -s' - includes directories
the 'find' solution above is recursive

largest FILE in the CURRENT directory
find . ! -name . -prune -type f -ls | sort -r -k 7,7 | head -1

Assuming the file name does contain embedded space [in ksh]:
A=$(find . ! -name . -prune -type f -ls | sort -r -k 7,7 | nawk 'FNR==1{print $NF; exit}')
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0