The UNIX and Linux Forums  


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
list the files with size in bytes balireddy_77 Shell Programming and Scripting 4 01-06-2009 01:17 PM
copying files from one location to another based on a list rebornhonest UNIX for Dummies Questions & Answers 4 11-30-2007 03:32 PM
Files list which are more than 300 MB size redlotus72 UNIX for Dummies Questions & Answers 2 09-14-2006 01:28 AM
Mail based on file size rajendragora UNIX for Dummies Questions & Answers 2 07-14-2006 07:53 AM
Command to list Files less than or equal to 2k size bache_gowda UNIX for Advanced & Expert Users 3 12-26-2003 12:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-08-2008
psiva_arul's Avatar
psiva_arul psiva_arul is offline
Registered User
  
 

Join Date: Jul 2007
Location: Bangalore, India
Posts: 97
how to List out the Files based on the file Size...?

Hi all,

i want to list put the files from one Directory order by size of the files order by ascending order.

i have written the simple command to list out the file name and file size, but its not listing as in ascending order.

ls -l|awk '{print $9 $5}'

output is Dir_files.ksh1108
FilesSize.ksh 241
LFiles.txt 64
Lfiles.txt 1340
List.txt 93
NoLines.ksh 73
PTH 50
add.ksh 202
ctl_name.log 226

So,Please guide me how to list out the files and file size in ascending order

Regards,
Siva.P
Bangalore
  #2 (permalink)  
Old 04-08-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,937
Here is one way ...


Code:
 ls -l | sort +4rn |awk '{print $9, $5}'

  #3 (permalink)  
Old 04-08-2008
helper helper is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 25
Use du command

du -sk * |sort -nr

This will do the need.
  #4 (permalink)  
Old 04-08-2008
ShawnMilo ShawnMilo is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 252
Simple -- use the -S flag on ls...

use -rS to print the largest last.
  #5 (permalink)  
Old 04-08-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
Quote:
Originally Posted by psiva_arul View Post
Hi all,

ls -l|awk '{print $9 $5}'
just add sort

Code:
ls -l|awk '{print $5,$9|"sort -n"}'

  #6 (permalink)  
Old 04-08-2008
ShawnMilo ShawnMilo is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 252
Quote:
Originally Posted by ghostdog74 View Post
just add sort

Code:
ls -l|awk '{print $5,$9|"sort -n"}'
Why are people still posting?

The ls command has a -S flag which does this. Or -Sr to reverse the order. Problem solved, and there is no better way possible. It's built in!
  #7 (permalink)  
Old 04-08-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
Quote:
Originally Posted by ShawnMilo View Post
Why are people still posting?
because i feel like it?
Quote:
The ls command has a -S flag which does this. Or -Sr to reverse the order. Problem solved, and there is no better way possible. It's built in!
not every ls has -S, but most *nix have sort (and du )
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 05:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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