Linux common command exercises: WC, cut, |, tee, tail

Source: Internet
Author: User

Linux Common command-related exercises:

1, only show how many lines of/etc/inittab file, other information does not display:

#wc-L/etc/inittab | Cut-d '-f1

[Email protected] ~]# Wc-l/etc/inittab | Cut-d '-f1

26

2. The number of files in the statistics/usr/bin directory:

#ls/usr/bin | Wc-l

[Email protected] ~]# Ls/usr/bin | Wc-l

1748

3. Take out the shell of all the users on the current system and request that each shell be displayed only once and in order;

#cut-D:-f7/etc/passwd |sort-u

[Email protected] ~]# cut-d:-f7/etc/passwd |sort-u

/bin/bash

/bin/sync

/sbin/halt

/sbin/nologin

/sbin/shutdown

4, thinking: How to display the content type of each file in the/var/log directory?

[[email protected] ~]# file/var/log/* or file ' Ls/var/log '

/var/log/anaconda.ifcfg.log:ascii text

/var/log/anaconda.log:utf-8 Unicode 中文版 Text

/var/log/anaconda.program.log:ascii 中文版 text, with very long lines, with overstriking

5. Take out the sixth line of the/etc/inittab file;

[Email protected] ~]# head-6/etc/inittab | TAIL-1 takes the first six lines and then takes the last line through the pipe

#

6. Take out the user name and shell of the 9th user in the/etc/passwd file.

Display to the screen and save it to the/tmp/users file;

[Email protected] ~]# tail-9/etc/passwd | head-1 | Cut-d:-f1,7|tee/tmp/users

Rpcuser:/sbin/nologin Tee content is displayed on the screen and saved to the specified directory

7. Display all files starting with PA in/etc directory, and count the number of them;    

[Email protected] ~]# ls-d/etc/pa* | Wc-l

4

8, do not use a text editor, add alias Cls=clear a line of content to the current user's. bashrc file;    

[Email protected] ~]# echo "Alias Cls=clear" >>.BASHRC

[Email protected] ~]# tail. BASHRC

Alias rm= ' Rm-i '

Alias cp= ' Cp-i '

Alias mv= ' Mv-i '

# Source Global Definitions

if [-F/ETC/BASHRC]; Then

. /etc/bashrc

Fi

Alias Cls=clear

Linux common command exercises: WC, cut, |, tee, tail

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.