Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

sort files by size

 
SOLVED
Go to solution
Alex Chupahin
Super Advisor

sort files by size

hello
please, simple question.
How to sort files in the directory by size.

Here is an example.
Whats wrong?

=============================================

$ if p1 .eqs. "" then $ p1 = "*.*"

$ close /nolog outfile
$ open /write outfile sys$manager:x.x
$ loop:
$ file = f$search( p1 )
$ if file .eqs. "" then $ goto done
$ cdt = f$file_attributes( file, "EOF" )
$! cdt = f$cvtime( cdt, "COMPARISON" )
$ write outfile -
cdt, -
" ", -
f$parse( file, , , "NAME" ),-
f$parse( file, , , "TYPE" )
$ goto loop
$ done:
$ close outfile
$ sort sys$manager:x.x sys$manager:z.z /key = (position:1,decimal)
$ type sys$manager:z.z
$ delete sys$manager:x.x.,z.z.


9 REPLIES 9
Joseph Huber_1
Honored Contributor
Solution

Re: sort files by size

SORT can't do 'variable length' keys (except floting point). You have to output the size in a fixed length field like:
$ size=f$fao("!8UL",cdt)
and then output size instead of cdt.

The sort command then is
$ sort sys$scratch:x.x sys$scratch:z.z /key=(position:1,size:8,decimal)


http://www.mpp.mpg.de/~huber
Highlighted
Mark Battle
Advisor

Re: sort files by size

For a directory tree listing do

$ dir/size [...]/nohead/wid=(filename=90,size=8)/out=space.txt
$ sort space.txt space.txt/key=(position:92,size:9,desc)
Joseph Huber_1
Honored Contributor

Re: sort files by size

and without intermediate files:

$ with bash shell: bash -c "ls -lS"

or

$ pipe direct/nohead/notrail/size/width=(DISPLAY=90,filename=80,size=9) 'p1' |-
sort/key=(position:82,size:10,descending) sys$pipe: sys$output | type sys$pipe:

(assuming directory+filenames are not longer than 80, or extent the width).
http://www.mpp.mpg.de/~huber
Kris Clippeleyr
Honored Contributor

Re: sort files by size

Hi Alex,

Use QDSB, downloadable from
http://www.quadratrix.be/qdsb.html

It's free.

Greetz.
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Alex Chupahin
Super Advisor

Re: sort files by size

>$ with bash shell: bash -c "ls -lS"

:) with bash, so I'm unix administrator for ten last years....

Unfortunately I have no practice with OpenVMS system administration, only for playing :(
Alex Chupahin
Super Advisor

Re: sort files by size

Thank you all
H.Becker
Honored Contributor

Re: sort files by size

Just my EUR .02...

Whatever the OP wants to use P1 for and whatever the expected output should look like,

$ bash -c "ls -lS" 'p1'
silently ignores the 'p1'

$ bash -c "ls -lS ''p1'"
requires a Posix style path in P1

and "ls -l" prints some noise. "ls -sS -c1" would come close, but the GNV version I tried seems to have problems to do the correct sort.

>>> $ pipe direct/nohead/notrail/size/width=(DISPLAY=90,filename=80,size=9) 'p1' |-
sort/key=(position:82,size:10,descending) sys$pipe: sys$output | type sys$pipe:

The OP seems to want only names and types. You may want to add a /sel=file=(nodevice,nodir,novers)
The OP had the default sorting order ascending. Anyway, here I would just sort to sys$output and omit the trailing pipe. But I would add another key to sort the file names as well.
Joseph Huber_1
Honored Contributor

Re: sort files by size

[
The OP seems to want only names and types. You may want to add a /sel=file=(nodevice,nodir,novers)
]

But then P1 also should be restricted to one directory only, otherwise all files in different subdirectories are listed without indication which one is in which directory!

Anyway a DIR & Sort script is not perfect,
Kris's QDSB is superior.
http://www.mpp.mpg.de/~huber
Alex Chupahin
Super Advisor

Re: sort files by size

It is very interesting why DEC/Compaq/HP will not include very useful /SORT option into DIR
as DEC in RT-11 DCL had done?
Very strange.