0

I was able to find the fifth largest file in the given sub-directory named foo by ls -Ss foo/*.csv | head -5 but this gives me largest five files. I wanted to extract only the fifth largest file, which would be the last one in this given list.

Then I found the number of characters in this file, which I was able to observe the list I found in the previous list. But what I wanted to do was to return only the fifth largest file and possibly pipe it to get the number of characters in this file.

Instead of getting top 5 largest files, how can I get the fifth largest file?

colbyjackson
  • 175
  • 2
  • 10
  • Possible duplicate of [Bash tool to get nth line from a file](https://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file). Use `... | sed -n 5p` – Socowi Jan 26 '19 at 23:24
  • I am looking for nth files from subdirectory not nth line from a file – colbyjackson Jan 26 '19 at 23:26
  • I know, but I thought you were able to make the transfer. `ls -Ss foo/*.csv` lists the largest files (usually) one per line. The largest file is at the top. So to print the 5th-largest file, all you have to do is to take `ls`' output and extract the 5th line. – Socowi Jan 26 '19 at 23:28
  • You could pipe to your line the `tail` command with 1 – shaiki siegal Jan 28 '19 at 06:38

0 Answers0