0

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.

3 Answers 3

1

Try this:

ls -S | head -n1
ls -S | tail -n1
2
  • 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, 2010 at 10:00
  • and also ls -s | head -n1 shows me also total number :/
    – user37158
    May 14, 2010 at 10:03
1
~# 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
1
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.

You must log in to answer this question.