Introduction to Linux environment variables
Environment variables: The bash shell uses an attribute called "Environment variable (environment variables)" To store information about the shell session and the working environment, which allows you to store data in memory to run program and script access on the shell, This data can be used to identify users, accounts, systems, shell features, and any other data that you need to store.
The environment variable in the shell has global environment variable and local environment variable, declare a local variable by the form of KV (variable=value), export this local variable, then upgrade to become global environment variable.
There are many ways to set up Linux, and there may be confusion. For example:
1. Do you know the difference between/etc/profile,/ETC/BASHRC, ~/.bash_profile, ~/.BASHRC?
2, Linux rc.local, INIT.D, Init, RC.D and other documents of the role and the difference is what?
See these, unavoidably some head big, today simply tidy up!
Copy Code code as follows:
/etc/profile,/ETC/BASHRC, ~/.bash_profile, ~/.BASHRC
/etc/profile: This file sets the environment information for each user of the system, and when the user logs on for the first time, the file is executed and the shell's settings are collected from the/ETC/PROFILE.D directory's configuration file.
/ETC/BASHRC: This file is executed for each user running the bash shell. When the bash shell is opened, the file is read.
~/.bash_profile: Each user can use this file to enter shell information dedicated to their own use, and the file is executed only once when the user logs on! By default, he sets some environment variables to execute the user's. bashrc file.
~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and each time you open a new shell.
Difference:
/ETC/PROFILE,/ETC/BASHRC is the
setting of the private environment variable in the system Global environment variable setting ~/.PROFILE,~/.BASHRC user Directory
Reading environment variables typically has three steps:
Copy Code code as follows:
First, read the Global environment variable set of document/etc/profile, and then read the additional settings based on their content, such as/ETC/PROFILE.D and/ETC/INPUTRC
Second, according to different user accounts, to other directories to read ~/.bash_profile, if this can not read on the read ~/.bash_login, this can not read will read the ~/.profile, the three document settings are basically the same, read a priority relationship
Third, and finally according to user account read ~/.BASHRC
~/.profile and ~/.BASHRC the same point:
Have personalized custom function
~/.profile can set the user's proprietary path, environment variables, etc., it can only login to execute once
~/.BASHRC is also a user-specific set of documents, you can set the path, command alias, each shell Script execution will use it once
Rc.local, INIT.D, Init, RC.D
Copy Code code as follows:
init file name, refers to the first script that the system starts
INIT.D directory name, the directory is placed in the various services of the startup script, such as sshd, httpd, etc.
The RCX.D directory name, and the following x represents each run level. There is a link file within the directory where each service launches a script within INIT.D, depending on the name of the linked file to start the state. K begins with service not started, S starts with service, X takes value 0~6 (RC.D,RC,RC0.D,RC6.D, etc.)
Rc.local link file, point to/etc/rc.d/rc.local. is the system initialization and services are started after the last execution of a script, some simple scripts can be placed in the
Linux Partial Command Introduction
Netstat
The Netstat command is used to display various network-related information, such as network connections, routing tables, Interface states (Interface Statistics), masquerade connections, multicast members (multicast memberships), and so on.
Common parameter
-a (all) displays all options, default does not show listen-related-
T (TCP) only shows TCP-related options-
u (UDP) displays only UDP-related options----
reject the alias display, and can display all numbers converted to numbers. -
L lists only the Listen (listening) service status-
p shows the program name of the associated link-
r displays routing information, routing table-
e Displays extended information, such as UID, etc.
by each protocol-
C Execute the netstat command at every other fixed time.
hint: The status of listen and listening can only be seen with-a or-l
ll command
ll commands the information listed in more detail, have the time, whether can read and write information.
ll lists all the file information under the file, including the hidden files, and ls-l only lists the explicit files, stating that the two commands are not equal!
PS command
This command is used to select and output the process running at a point in time, and its common parameters are as follows:
-A: All processes are displayed.-A
: All processes not related to terminal-
u: Related processes for valid users-
x: Typically used with A parameter to list more complete information-
L: Long, more detailed list of PID information
In fact, we just remember that PS commonly used in the command parameters to match, they are not many, as follows:
PS aux # View system All process data
PS Ax # View all processes not related to terminal
Ps-la # View system All process data
PS AXJF # View along with part of the process tree state
Kill command
This command is used to send a signal to a work (%jobnumber) or to a PID (number), which is usually used in conjunction with the PS and Jobs commands, and its basic syntax is as follows:
The common parameters of signal are as follows:
Note: The first number is the signal code, the use of the code can be used to replace the corresponding signal.
1:sighup, start the terminated process
2:sigint, equivalent to input CTRL + C, interrupt the 9:sigkill of a program
, force the interruption of a process
15:sigterm, terminate the process in the normal way to end the process
17:sigstop, equivalent to input ctrl+z, suspend a process
For example: In the normal end of the process to finally the first background work, you can use the Jobs command to view the first work process in the background
Re-change Process ID PID process, PID can be used with the PS command through the pipeline command plus grep command to filter to get
Wget
1. Download a single file using wget
wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.3.tgz
2. Use Wget-o to download and save with different filename
3, the use of Wget–limit-rate speed limit Download When you perform wget, it defaults to occupy all possible broadband downloads. But when you're ready to download a large file and you need to download other files, it's necessary to speed it down.
4. Use the Wget-c breakpoint to continue using Wget-c to restart download interrupted files:
It is very helpful for us to download large files suddenly because of interruptions such as network and so on, we can continue downloading instead of downloading a file again. You can use the-c parameter when you need to continue interrupting downloads.
5, the use of wget-b background download for downloading very large files, we can use the parameter-B for background download.
Wget-b Http://www.haorooms.com/haorooms-3.1-zh_CN.zip
Continuing in background, PID 1840.
You can use the following command to view the download progress
Tail command
The tail command writes the file to the standard output from the specified point. Using the-f option of the tail command makes it easy to refer to the changing log file, Tail-f filename will display the tail contents of the filename on the screen, and not only refresh, so that you see the latest file content.
1. command format;
tail[necessary parameters [select parameters] [file]
2. Command function:
Used to display the content at the end of a specified file and to process it as input when no file is specified. Common view log files.
3. Command parameters:
-F Circular Read
-Q does not display processing information
-V display detailed processing information
-c< number > displayed bytes-n< number of
rows > number of rows
--pid=pid with-F, expressed in the process ID, The PID ends when it dies.
-Q,--quiet,--silent never outputs the first-s of the file name
,--sleep-interval=s is shared with-F, which means sleeping s seconds at each repeated interval
The following command shows 5 lines at the end of the file
Curl Command
Can view the website, also can download the file!
In Linux, Curl is a file transfer tool that uses URL rules to work at the command line, and is a powerful HTTP command-line tool. It supports file upload and download, is a comprehensive transmission tool, but by tradition, the custom called URL as the download tool.
Grammar:
Common parameters:
-a/--user-agent <string> Set User agent sent to server
-b/--cookie <name=string/file> cookie string or file read location
-c/ Write the cookie to this file after the--cookie-jar <file> operation
-c/--continue-at <offset> Breakpoint continues
-d/-- Dump-header <file> writes header information to the file
-e/--referer Source URL
-f/--fail failed to display HTTP error when connection fails
-o/--output writes the output to the file
-o/--remote-name writes the output to the file, keeping the file name of the remote file
-r/--range <range> retrieves the
-s/--silent mute mode from the http/1.1 or FTP server byte range . Do not output anything
-t/--upload-file <file> upload files
-u/--user <user[:p assword]> set up the user and password for the server
-w/--write-out [format] what output is finished
-x/--proxy
Summary
About the environment variables and commands introduced to this, in fact, there are many Linux commands, the above command is I often used, to have the needs of friends for reference.