1、

 head FileName 只显示文件的前10行 (默认)

tail FileName     只显示文件的后10行  (默认)

如:

[root@localhost test]# nl sizeof.c
     1  #include <stdio.h>
     2  #include <string.h>
      
     3  fun(int *a)
     4  {
     5  printf("%d\n",sizeof(a));
     6  printf("%d\n",strlen(a));
     7  }
     8  int main()
     9  {
    10          int b=34;
    11          int a[]={1,2,3,4,5,6,7,8,9};
    12          printf("%d\n",sizeof(b));
    13          printf("%d\n",strlen(b));
    14          fun(a);
    15  return 0;
    16  }
[root@localhost test]#


显示前10的内容:

[root@localhost test]# head sizeof.c
#include <stdio.h>
#include <string.h>

fun(int *a)
{
printf("%d\n",sizeof(a));
printf("%d\n",strlen(a));
}
int main()
{
[root@localhost test]#

显示后面10行内容:

[root@localhost test]# tail sizeof.c
}
int main()
{
        int b=34;
        int a[]={1,2,3,4,5,6,7,8,9};
        printf("%d\n",sizeof(b));
        printf("%d\n",strlen(b));
        fun(a);
return 0;
}
[root@localhost test]#

 

2、head –n FileName 显示文件的前n行

[root@localhost test]# head diff-1.c diff-2.c
==> diff-1.c <==
#include <stdio.h>

int main()
{
        prinftf("hello word ... \n");
return 0;
}

==> diff-2.c <==
#include <stdio.h>
#include <string.h>
int main()
{
        printf("hello word ... \n");
return 0;
}
[root@localhost test]#
 

 [root@localhost test]# head -n 5 sizeof.c
#include <stdio.h>
#include <string.h>

fun(int *a)
{
[root@localhost test]#
 
3、tail –n FileName 显示文件的后n行
 
[root@localhost test]# tail -n 4 sizeof.c
        printf("%d\n",strlen(b));
        fun(a);
return 0;
}
[root@localhost test]# 
 
4、 打印head-1.txt, head-1.txt的前10行
 ==> head-1.txt <==

head-1.txt内容

==> head-2.txt <==

haed-2.txt内容