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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.