List by size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List by size
# 1  
Old 07-21-2017
List by size

I am trying to create a script to list files by size. I was able to show a long listing before adding parameters (first comment) but nothing seems to work after trying to add them. If the first or only parameter is -r the output should be descending order by size, if the parameter is anything else like "*.c" it should list all C programs before passing the output to the grep and sort.

The script says if found "-r" when it isn't there and vice versa and entering a star name parameter expands to the first occurrence of the specified item.

All ideas appreciated. TIA
Code:
rev=""
if [ $# -gt 0 ]
  then
  if [ $1 -eq "-r" ]
  then
    rev="-r"
    echo found -r
    shift
  fi
fi
#ls -l |grep -v "total " |sort +4n -5 +8
#ls -l $1 |grep -v "total " |sort $rev +4n -5 +8 |more -e
echo ls -l $1 grep -v "total " sort $rev +4n -5 +8 more -e

# 2  
Old 07-21-2017
Try using:
Code:
ls -lrS

also:
Code:
if [ "$1" = "-r" ]

( -eq is for numerical comparisons )
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 07-21-2017
I couldn't get the "-lrS" to fly, but the equal sign does the trick.
Thank you.
Code:
rev=""
if [ $# -gt 0 ]
  then
  if [ $1 = '-r' ]
  then
    rev="r"
    echo $rev
    shift
  fi
fi
ls -l $* |grep -v "total " |sort +4n$rev -5 +8 |more -e

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

List of file name with size

how to get the file name list with size descriptive in hp-ux Required output: permission link user group size(with MB,KB,GB etc) date time name (7 Replies)
Discussion started by: Jewel
7 Replies

2. Shell Programming and Scripting

Need to get the list of file with size in AUX

to get the list of file name with size Example: rwxrwxrwx 1 cm x 562KB Nov 6 19:22 a rwxrwxrwx 1 cm x 562MB Nov 6 19:22 a edit by bakunin: Please view this code tag video for how to use code tags when posting code and data. (5 Replies)
Discussion started by: Jewel
5 Replies

3. UNIX for Dummies Questions & Answers

Command to list our directory size

Is there any command that can list out all the files size including directory in 1 command? `ls` will only give 2048 for a directory, which i'm looking for the actual size. (5 Replies)
Discussion started by: lsy
5 Replies

4. UNIX for Dummies Questions & Answers

list only size and path

what command should i use for listing only the size and path of files ? (3 Replies)
Discussion started by: g0dlik3
3 Replies

5. UNIX for Dummies Questions & Answers

How to list files which have same size?

Hi guys, I need to do 100 files comparison after I sorted the files. There are no specific key for sorting so i plan to arrange the files based on the file size. The command that i used to sort the files by size is as per below:- ls -l | sort +4rn | awk '{print $5, $9}' The problem that i... (3 Replies)
Discussion started by: shahril
3 Replies

6. UNIX for Dummies Questions & Answers

How to get size of a list of files with specified extension?

Command ls -l *cpp lists all cpp program files in a directory. It shows the size of each file. Using a calculator to work out the total size of the cpp files would be very tedious. Is there a way to get the total size from the command line? (5 Replies)
Discussion started by: resander
5 Replies

7. UNIX for Dummies Questions & Answers

List size information...

hi all, i want to list only the size information and name of the file(s) and directories in current directory .. (2 Replies)
Discussion started by: sonu_pal
2 Replies

8. UNIX for Dummies Questions & Answers

How to list a file size, but not its name?

If I have a file x.txt that is 8 bytes... I want to enter >> x.txt 8 I've played around with ls, and du... and they always list the file name. (2 Replies)
Discussion started by: ordano
2 Replies

9. Shell Programming and Scripting

list the files with size in bytes

hi all plz help in listing the files with size in bytes. thnks -Bali (4 Replies)
Discussion started by: balireddy_77
4 Replies

10. UNIX for Dummies Questions & Answers

List File size

Hello all, I have a directory filling up. I need to determine the size of the files in the directory. How do I do that, what command should I run when I am in the directory? Next question, can I expand the partition size? (10 Replies)
Discussion started by: komputersman
10 Replies
Login or Register to Ask a Question