How do I find the third largest file and read first 5 lines
I tried below to get the third largest file
ls -s /file/path | head 3 | tail -1
How do I use this file name to read the first 5 lines and insert to a new file?
CodePudding user response:
You are very close, you just forgot to capitilize -s
and you forgot to put dash in front of the number in head 3
ls -S /file/path
That works to output a list of files sorted by size.
head -3
Then you need to put a dash in front of your option for head
just like you did with tail -1
.
To read a certain number of lines from a file you can use head
in the same way and provide it a filename.