-1

1.How to view the largest file in the directory using linux commands.

2.As i followed the following command ls -lh.

3.Is any other way to use the linux commands to view the largest file inside the directory with its size in human readable format.

Sana
  • 25
  • 7

3 Answers3

0

Try:

$ find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head

It will give you the top 10 in your directory. And if you just want the largest one:

$ find . -type f | xargs ls -1S | head -n 1

With its "parameters/attributes" (size, permissions, creation date & time):

$ find . -type f | xargs ls -lS | head -n 1

And if youy want to use ls without find try:

$ ls -S . | head -1

Idos
  • 15,053
  • 14
  • 60
  • 75
0
ls -Slh | tail +2 | head -1

which uses ls to list your files in size order, long format with human readable sizes. tail +2 removes the first line of your output which is a total size and head gives you the largest file.

Neil Masson
  • 2,609
  • 1
  • 15
  • 23
  • Can you tell me the need of tail in this comment@Neil Masson – Sana Dec 16 '15 at 11:45
  • `ls` gives me `total 59464` followed by `-rw-r--r--@ 1 nmasson staff 23M 25 Nov 03:43 gc.log`. The `tail` says start at the second line, skipping the total line. – Neil Masson Dec 16 '15 at 11:52
0

I solved the question using this command:

ls -Slh | head -2

This lists by size and selects the first two results.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Sana
  • 25
  • 7