Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.