Sponsored Content
Full Discussion: List by size
Top Forums Shell Programming and Scripting List by size Post 303000887 by wbport on Friday 21st of July 2017 04:35:09 PM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy