Shell finishing (37) = = = Variable understanding and two exercises

Source: Internet
Author: User
Tags disk usage

1/etc/profile

2 ~/.bash_profile

3 ~/.BASHRC

4 $PATH


Where/etc/profile is the global environment variable that takes effect for all users, while. Bash_profile only works on the current user.


~/.bash_profile: Each user can use this file to enter shell information dedicated to their own use, when the user logs on, the file is only executed once! By default, he sets some environment variables, Executes the user's. bashrc file. Simply put the script path in here, and every time the user logs in, the script in the script path will be executed.

~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and every time you open a new shell. (Each user has a. bashrc file in the user directory) simply put the script path in the face. Each open shell executes the script in the script path.


$PATH: determines which directories the shell will look for commands or programs, the value of PATH is a series of directories, and when you run a program, Linux searches for compiled links in these directories.

Edit your PATH declaration in the following format:

 Path= $PATH: <path 1>:<path 2>:<path 3>:------: <path n>

  You can add the specified path yourself, separated by a colon. When the environment variable is changed, it takes effect the next time the user logs on, and if you want to take effect immediately, you can execute the following statement: $ source. bash_profile

It is important to note that it is best not to put the current path "./" in path, which may be subject to unexpected attacks. When you are finished, you can view the current search path through the echo $PATH. With this customization, you can avoid frequent launches of programs that are outside the path of the shell search.




Two exercises after class

(1) Write a login welcome script for the root user, report the number of processes in the current host, the logged-on user, the disk usage of the root file system, and when logged in from a TTY terminal, the effect shown is as follows.

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/08/2A/wKiom1ndFeehTwEFAAAps37pNtc997.png-wh_500x0-wm_ 3-wmp_4-s_2002741956.png "title=" capture. PNG "alt=" Wkiom1ndfeehtwefaaaps37pntc997.png-wh_50 "/>

Recommended steps:

(1) New script file welcome.sh for outputting various monitoring information.

(2) Modify the/root/.bash_profile file to invoke the welcome.sh script.

The script is as follows:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/A6/DC/wKioL1ncp9fx4G07AAAcnbRtadA616.png-wh_500x0-wm_ 3-wmp_4-s_3193224519.png "title=" capture. PNG "alt=" Wkiol1ncp9fx4g07aaacnbrtada616.png-wh_50 "/>

Add the following path in/root/.bash_profile:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/A6/DC/wKioL1ncqEbwB0jiAAAeuDLQAk8985.png-wh_500x0-wm_ 3-wmp_4-s_1779140689.png "title=" capture. PNG "alt=" Wkiol1ncqebwb0jiaaaeudlqak8985.png-wh_50 "/>

(2) write Start, stop, status three script programs to start, stop various system services. For example, you can stop and start the Crond service by directly executing the stop crond \start crond command.

The path variable is used to set the default search path for executable programs, and when a command program is specified with only the name of the file, the Linux system looks for the corresponding executables in the directory range specified by the path variable, and if not found, prompts "command not found"


View $path Path

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/A6/DC/wKioL1ncqnvipYnTAAAR6h_Snng305.png-wh_500x0-wm_ 3-wmp_4-s_319187733.png "title=" capture. PNG "alt=" Wkiol1ncqnvipyntaaar6h_snng305.png-wh_50 "/>

We can see the/root/bin, we put the start.sh script under/root/bin/.

The contents of the start.sh script are as follows:


650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/08/2A/wKiom1ndGuay-JLVAAAXOplueEw379.png-wh_500x0-wm_ 3-wmp_4-s_178431012.png "title=" Capture 1. PNG "alt=" Wkiom1ndguay-jlvaaaxoplueew379.png-wh_50 "/>

To add an alias in ~/.BASHRC:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/08/2A/wKiom1ndG1jhuz7lAAAmbknAd6k830.png-wh_500x0-wm_ 3-wmp_4-s_3055640727.png "title=" Capture 1. PNG "alt=" Wkiom1ndg1jhuz7laaambknad6k830.png-wh_50 "/>

The output results are as follows:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/08/2A/wKiom1ndG3fBAXq4AAAmYT1oRyA195.png-wh_500x0-wm_ 3-wmp_4-s_1405353866.png "title=" capture. PNG "alt=" Wkiom1ndg3fbaxq4aaamyt1orya195.png-wh_50 "/>


Summarize:

The script is not important, this article mainly wants to tidy up these important documents, very useful.

This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1971265

Shell finishing (37) = = = Variable understanding and two exercises

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.