How do you view a part of a file in Linux?

Source: Internet
Author: User
Keywords Linux
Tags aliyun etc example file http linux mail nfs

If you only want to see the first 5 lines of the file, you can use the Head command,
such as: Head-5 passwd
If you want to view the following 10 lines of the file, you can use the tail command,

Example:

[Root@localhost software]# head-5 passwd

Root:x:0:0:root:/root:/bin/bash &http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp;bin:x:1:1:bin:/bin:/ Sbin/nologin Daemon:x:2:2:daemon:/sbin:/sbin/nologin Adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/ Lpd:/sbin/nologin

such as: TAIL-10/ETC/PASSWD

Example:

[Root@localhost software]# tail-10/etc/passwd

Abrt:x:173:173::/etc/abrt:/sbin/nologin rpcuser:x:29:29:rpc Service User:/var/lib/nfs:/sbin/nologin nfsnobody:x : 65534:65534:anonymous NFS user:/var/lib/nfs:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin sshd:x:74:74: privilege-separated Ssh:/var/empty/sshd:/sbin/nologin Tcpdump:x:72:72::/:/sbin/nologin sunco:x:500:501::/home/ Sunco:/bin/bash Ldap:x:55:55:ldap user:/var/lib/ldap:/sbin/nologin Mysql:x:501:502::/home/mysql:/bin/bash www:x : 502:503::/home/www:/bin/bash

Do you know how to view the middle section of a file? You can use the SED command
such as: Sed-n ' 5,10p ' passwd

This allows you to view only lines 5th through 10th of the file.

Example:

[Root@localhost software]# sed-n ' 5,10p ' passwd

Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin Sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/ Shutdown Halt:x:7:0:halt:/sbin:/sbin/halt Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin uucp:x:10:14:uucp:/var/ Spool/uucp:/sbin/nologin
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.