Do you think the way I'm doing it is fine? Is this the most typical way to do it? Share your thoughts please.
# Display the last three lines of a text file with line numbers in reverse order # Can come quite in handy when reading log file entries cat -n [FILE] | tac | head --lines=3
# Let's create a text file to test our command against cat > test.txt # Copy and paste these lines into the terminal window and press Ctrl+D to let # the shell know that we're done entering our stuff house car boy cat lake sea laptop rain # Run the command cat -n test.txt | tac | head --lines=3 # Brief description: # cat -n test.txt | - Pipe the output with line numbers to the tac command # tac | - Reverse the order and pipe along to the head command # head --lines=3 - Display only the first three lines # Output: 8 rain 7 laptop 6 sea # The number next to the first line in our output (8 rain) should be equal to # the number of lines in the entire file. We can check that using the word count # utility: wc -l test.txt # Output (It's 8 too. Looks like the test passes): 8 test.txt