Introduction to basic commands under Linux (vii)

Source: Internet
Author: User
Tags stdin

I. I/O redirection:

System settings

Default output device: Standard output, STDOUT, 1

Default input device: standard input, STDIN, 0

Standard error Output: STDERR, 2

Standard input: Keyboard

Standard output and Error output: Display

Redirect to change the source and destination of the data

1. Output redirection:

> overwrites the contents of the original file

>> Append Output

SET-C: Prohibit overwrite redirection for already existing files;

Force overwrite output, use >|

Set +c: Turn off the above features

2>: Redirect Error output

2>>: Append method

&>: Redirect standard output or error output to the same file


<: Input redirection

<<:here Document

Two. Piping

The output of the previous command, as input to the latter command

Usage: Command 1 | Command 2 | Command 3 | ...

1.echo "Luochen" | Tr ' A-Z ' A-Z

2.echo "Luochen" | passwd--stdin Root

3.cut-d:-f1/etc/passwd | Sort-n | Tr ' A-Z ' A-Z

4.ls/var | Tr ' A-Z ' A-Z

5.tee command obtains data from standard input and saves data to a file at the same time to standard output data

6.wc-l/etc/passwd | Cut-d '-f1

7.ls/usr/bin | Wc-l


Practice:

1, Statistics/usr/bin/Directory of the number of files

# Ls/usr/bin | Wc-l

2. Take out the shell of all the users on the current system, require that each shell be displayed only once, and be displayed sequentially

# cut-d:-f7/etc/passwd | Sort-u

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

# file ' Ls/var/log '

4. Remove the 6th line of the/etc/inittab file

# head-6/etc/inittab | Tail-1

5. Take out the user name and shell of the 9th user in the/etc/passwd file, display it to the screen and save it to the/tmp/users file.

# tail-9/ETC/PASSWD | head-1 | Cut-d:-f1,7 | Tee >/tmp/users

6. Display all files starting with PA in/etc directory and count them

# ls-d/etc/pa* | Wc-l

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

# echo "Alias Cls=clear" >> ~/.BASHRC










This article is from "Luo Chen's blog" blog, please be sure to keep this source http://luochen2015.blog.51cto.com/9772274/1635498

Introduction to basic commands under Linux (vii)

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.