Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

Try this:

ls -S | head -n1
ls -S | tail -n1
share|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
~# 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
share|improve this answer
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.