Shmuel
Shmuel

Reputation: 55

How to print only the largest file in a directory in Linux?

I would like to know how can i sort a directory and print out to the terminal only the largest file in that specific directory? This is my directory:

file1 2
file2 3
file3 1
file4 5
file5 2

The wanted result is to print "file4" to the terminal

Upvotes: 0

Views: 1432

Answers (1)

bsyk
bsyk

Reputation: 2029

For just files in the directory you can use this:

ls -Shld * | head -n 1

To include directories you can us du:

du -a * | sort -n -r | head -n 1

Upvotes: 3

Related Questions