I am wondering if there is a Terminal command which will specifically list the 5th file in a directory. I was initially using the ls | head -5 command to complete this, however it listed all other files as well as the fifth, an action which is undesirable for the purpose i have in mind for the proposed command.

Thanks in advance.


In addition to head, use the tail command:

ls | head -5 | tail -n 1

where the -n 1 argument displays the last line of the input.

For more info on the command, type man tail in Terminal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .