I have a task to write a bash script showing permissions to biggest and smallest file in catalog. How I could obtain that ?

I've tried ls -s but it shows me all files sorted by the size.

link|improve this question
feedback

3 Answers

Try this:

ls -S | head -n1
ls -S | tail -n1
link|improve this answer
ok, and now I have something like this "4 -rw-r--r-- 1 s7809 Domain Users 299 2010-04-30 12:14 skrypt.txt" . How to display only permissions and filename ? – user37158 May 14 '10 at 10:00
and also ls -s | head -n1 shows me also total number :/ – user37158 May 14 '10 at 10:03
feedback
~# ls -hlS | head -n2 | tail -n1 | awk '{print $1, $8}'
-rw-r--r-- openssl-0.9.8k.tar.gz

~# ls -hlS | tail -n1 | awk '{print $1, $8}'
-rw-r--r-- a.php

 ~# du -sh openssl-0.9.8k.tar.gz a.php
3.7M    openssl-0.9.8k.tar.gz
4.0K    a.php
link|improve this answer
feedback
ls -lS | grep - | head -n1 | awk '{print $1," ",$8}'
ls -lSr | grep - | head -n1 | awk '{print $1," ",$8}'

Take note of -S instead of -s as that only adds the file size in blocks and does not sort.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown