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.
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
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.
I solved the question using this command:
ls -Slh | head -2
This lists by size and selects the first two results.