Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of commonly used commands under CentOS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "summary of commands commonly used under CentOS". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Commands related to input and output

1) echo command echo:

Common options: e: disable escape characters (default); e: enable escape characters; n: do not wrap at the end of the output

2) receive user input command read: format: read [[option] parameter] name;read command is used to read characters, which can come from standard input or text slave.

Common options: a: put the entered text into an array by field (the default delimiter is space or tab tab), with the array subscript starting at 0; d: specify the Terminator, and when the specified Terminator appears in the input, the read command will assume that the input has ended (the default uses the newline character as the Terminator) E: when reading from standard input, use the Readline library to get input (at this time, the user can use the backspace key, the direction key for simple line editing operation); n: specify the number of characters to be read n * p: output the string specified by this option to standard error and read the input.

R: put the read string into different variables by field; s: lock the screen before reading characters from standard input.

T: if the user does not enter within the specified time, the read status (in seconds) ends; u: read from the specified file descriptor.

Example: read multiple data and save them in an array

The code is as follows:

Read-a name;echo "names are:$ {name [*]}"

3) display and save text command the tee:tee command divides the obtained data (usually from a pipe) into two copies, one to standard output and the other to a specified file. Format:. | | tee [options] filename |

Common options: a: write data to the end of the file as an append; I: standard error is not written when writing input data.

For example, ifconfig eth3 | tee eth3_info; if you want to append write, you can add the-an option after tee.

4) Mail command mail

A) send email: command format: mail [option] [- s subject] [- c c_adress] [- b b_adress] user [- a file]...

Common options: n: do not read the settings file / etc/mail.rc (this file allows users to send mail using an external address rather than the system's own sendmail); s: set the chairman information of the message; c: use a BCC list; b: use a CC list.

Usage: when sending an email, you usually put the body of the message into a file, and then use redirection to read and send the contents of the file. For example, send the contents of the file net_info to users root and user1, and set the subject of the message to net_info:

The code is as follows:

Mail-s "net_info" root,user1

The code is as follows:

Mail-s "net_info" root,user1,4065*@qq.com

4065*@qq.com can receive a message from user@localhost.localdomain (because user@localhost.localdomain is not a returnable email address, some mailboxes may reject such messages).

B) check email

Sometimes users in the system may receive the following prompt: the You have new mail in / var/spool/mail/root message tells the user to receive a new system email.

(1) you can view the mailing list using mail: mail. After using the mail command, a mailing list will be displayed, in which the first two lines are the version number of the message, the total number of messages and the number of unread messages, etc.; in the subsequent mailing list, ">" indicates the location of the current cursor, U indicates unread messages, and the climate is the serial number, sender, sending time, subject of the message, and so on. The "&" on the last line is the mail command prompt at which the user can enter the command and view the message. The commands commonly used at the mail command prompt are as follows:

H: check the title of the message

D: use this command to add a serial number to delete the specified message

F: view the message specified by the current cursor

N: a message that jumps to a specified serial number

Q: exit and save the read mail to the file ~ / mbox

X: exit

! Shell command is allowed

(2) it is generally recommended to use the command Q to exit in order to save the read mail into the file ~ / mbox. If you want to reread the messages in mbox, you can use the option f:mail-f

(3) administrators can also use-f to view the emails of other users: mail-f / var/spool/mail/user1

5) start the new Shell command exec:exec to start a new shell and execute the specified command in the new shell. In practical applications, the exec command is often used to process file descriptors, and at this time (and only at this time) exec does not start a new shell to replace the current shell.

Command format:

The code is as follows:

Exec shell-command

Such as: exec 3

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report