How to output the first line from every file in Linux?

Member

by gaston , in category: General Help , a month ago

How to output the first line from every file in Linux?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , a month ago

@gaston 

To output the first line from every file in Linux, you can use the head command in combination with a file globbing pattern. Here's the command:

1
head -n 1 *


Explanation:

  • head is a command used to print the first lines of a file.
  • The option -n 1 specifies that we only want the first line.
  • The asterisk * is a file globbing pattern that matches all files in the current directory.


When you run this command, it will display the first line of every file in the current directory.