Gnu/linux Review notes (2)

Source: Internet
Author: User

---io redirection:

The typical von Neumann computer consists of 5 major components: an operator, a controller, a memory, an input device, and an output device. And a computer may have many input devices and output devices, keyboards, microphones are input devices, monitors, sound cards are output devices, network cards, hard disks, USB sticks are both input devices and output devices. So many input system set the default input device is the keyboard, also known as the standard input, with stdin, file descriptor 0; The default output device is a display, also known as the standard output, with stdout, the file descriptor is 1; The default error output is also a monitor, denoted by stderr, The file descriptor is 2. Although both standard output devices and standard error output devices are displays, they are actually different streams of data. IO redirection is the redirection of the default input output to another device or file.

Standard output redirection symbols:

>: Overwrite output redirection

>| : Force overwrite redirection

>>: Append override redirect

The SET command is a built-in command of bash that changes the shell properties and positional parameters, as described in Help set, where set-c is used to turn off output redirection, set +c turn output redirection

Example:

Ls/var >/tmp/var1.txt originally Ls/var output will be printed on the screen, but at this point is redirected to the/tmp/var1.txt file.

Ls/varr >/tmp/var2.txt bash prompt ls: cannot access '/varr ': There is no file or directory because Ls/varr is an error output and cannot be redirected using standard output, to redirect should be made With standard error redirection ,

ls. Varr 2>/tmp/var2.txt

Standard Error Output Redirect:

2>: Overwrite error output redirection

2>>: Append error output redirection

Is it possible to redirect standard output and redirect standard error output? Of course there is.

&> indicates redirection standard output or standard error output

Enter redirection:

<: Input redirection

Wc-l </etc/passwd calculate the number of rows for a passwd file

<<: Generate documents here, in this way you can generate documents in scripts such as:

Cat >>/tmp/myfile.txt << EOF redirects the user's input from the terminal to the/tmp/myfile.txt file until the user enters EOF to end the input

---Pipeline:

COMMAND1 | COMMAND2 | COMMAND3

The meaning of a pipeline is to use the output of the previous command as input to the latter command

Ls/var | Tr ' A-Z ' A-Z

The output has been replaced with uppercase

BACKUPS
CACHE
Lib
LOCAL
LOCK
LOG
MAIL
Opt
RUN
SPOOL
Tmp
Www
Give some examples:

1. Find the number of/etc/passwd files

Wc-l/etc/passwd | awk ' {print '} '

Wc-l/etc/passwd | Cut-d ""-f1 single or double quotation marks here.
2. Remove the default shell for all users on the current computer, requiring each shell to be displayed only once and sequentially output

cat/etc/passwd |    Awk-f: ' {print $7} ' | Sort-u

cat/etc/passwd |   Cut-d:-f7 | Sort-u

3. Display the type of each file in the Var/log directory

sudo file/var/log/*

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

cat/etc/passwd |   head-6 | Tail-1

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

cat/etc/passwd |   head-9 |    Tail-1 |  Awk-f: ' {print $1,$7} ' | Tee/tmp/users

cat/etc/passwd |  head-9 | Tail-1 | Cut-d:-f1,7

  

Gnu/linux Review notes (2)

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.