The shell finds the first ten files ending with .sh in the /tmp directory, and saves the first line of each file to another file

1. Find the first ten files ending with .sh in the /tmp directory, and then save the first line of each file to another file

 
 
#!/bin/bash #qq:2575815569 for i in `find /tmp -type f -name "*.sh" |head -n 10`; do sed -n '1p' $i >>new echo ”complete!” done

Notes:
for  i   in Define the variable i as
find Find command (format: find-type-content)
-type f type is plain text
-name specified content
*.sh ends with .sh
head -n 10 Display the first ten lines in positive order (the head is displayed in positive order, -n 10 specifies the number of lines and 10 lines)
do和done do is interpreted as then in the for statement, done is the end
but -n '1p' Edit the first line (sed edit text command, -n specifies the number of lines, 1p means the first line)
$  >> $ indicates a variable followed by the variable name, >> appends the output to

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324778295&siteId=291194637