Skip to content
Advertisement

Linux is there a way to list a specified number of lines in a repository and sub repositories

I want to write a shell script which takes as input a valid path, and the script lists the first n (also a parameter) lines of all the files from the repository and sub repositories where the user who launched the script has read and write privileges.

Is there a command that would allow me to do this? I believe that n would be written like $1 to indicate that it is a parameter, but I am not sure what command to go with to list the lines of all the files from the repository.

I apologize if this is a simple solution, I am just currently baffled.

Advertisement

Answer

find . -type f -readable -writable -exec head -$1 {} +

Pass the number of lines to print as a parameter and then find all files in the current directory structure that are both readable and writable. Execute head with the passed parameter on as many files as possible with each exec (using +)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement