次のようなファイルがある時
$ cat 1.txt
1-1
1-2
1-3
1-4
1-5
1-6
1-7
1-8
1-9
$ cat 2.txt
2-1
2-2
2-3
2-4
2-5
2-6
2-7
2-8
2-9
$ cat 3.txt
3-1
3-2
3-3
3-4
3-5
3-6
3-7
3-8
3-9
次のコマンドで、各ファイルの冒頭と末尾の指定行数を表示させる
$ find ./* -type f | xargs -I{} sh -c "(echo -e '{}\n-'; head -2; echo -e '---'; tail -2;echo -e '---------\n---------') < {}"
./1.txt
-
1-1
1-2
---
1-8
1-9
---------
---------
./2.txt
-
2-1
2-2
---
2-8
2-9
---------
---------
./3.txt
-
3-1
3-2
---
3-8
3-9
---------
---------
参考記事
find 結果それぞれにパイプ・リダイレクトを含むコマンドを適用する
Linux > Link > head / tail > (head; tail) < file.txt > 先頭と最後を同時表示