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.
|
feedback
|
|
Try this:
| |||||
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
| |||
|
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. | |||
|
feedback
|