Use of Shell in Linux

Source: Internet
Author: User

1. Basic shell Parameters
# Cat/etc/shells System shell location
# Bsh, csh, ksh, and bash change the shell environment of the root user
# Chsh changes the shell environment of common users
# More/etc/passwd view shell environments of all users2. shell Variables2.1. Environment Variables
# Set | more view environment variables2.2 Introduction to common environment variables
# Echo $ USER display current USER login name
# Echo $ UID: displays the user ID of the current user
# Echo $ SHELL: shows the current user's login Shell
# Echo $ HOME displays the HOME Directory of the current user
# Echo $ PWD: display the directory of the current user
# Echo $ PATH indicates the command search PATH of the current user
# Echo $ PS1 displays the current user's primary prompt
# Echo $ PS2 display the current user's secondary prompt2.3 environment variable configuration file
# Ls-l/etc/bashrc/etc/profile: display the global configuration file of Environment Variables
The "bashrc" file is used to define global functions and aliases. The file content is applicable to non-interactive Shell and non-Logon Shell in addition to setting for all login users in the system.
The "profile" file sets the global environment and applies it to all users who log on to Shell # ls-l/home/username /. bash_profile/home/username /. bashrc displays the configuration file of User username
# Cd/etc/skel enter the initial user configuration file
# Cp. bash_logout. bash_profile. bashrc. emacs. gtkrc/home/username: copy the initial configuration file of the user to the home Directory of the User username (used when the user fails to set the configuration file)2.4 location Variables
Format: $ n from 1 to 9
Single quotation marks (''): do not replace any variable, keep the original value of the string
Double quotation marks (""): Replace with the variable value and use it as part of the string.
Reverse quotation marks (''): Used to replace commands. The execution result of commands in quotation marks replaces the command itself as a string.2.5 pre-defined Variables
# Echo $ # variable indicating the location parameter
# Echo $ * indicates the location parameter content
# Echo $? Indicates the status returned after the command is executed. It is used to check whether a command is correctly executed. In Linux, if the command exit status is 0, the command is correctly executed. If the value is not 0, the command execution error is returned.
# Echo $ indicates the process Number of the current process
# Echo $! Indicates the last process number running in the background
# Echo $0 indicates the name of the currently executed process2.6. User-Defined variables
# Variable name = variable value DAY = Sunday
# Echo $ variable name echo $ DAY
# Unset-f-v name2.7 common Bash Functions
# View history commands
# History-c command history clearing2.8 command alias
# Alias command = 'new command 'Alias ll = 'LS-l' Replace the ls-l command with ll alias
# Unalias-a name cancelling command alias
# Cd/etc/profile. d/view the system alias definition file
3. Pipelines and redirection3.1 input redirection
# Wc/etc/passwd the number of characters, words, and lines in the/etc/passwd file
# Wc </etc/passwd redirects the content input in the "/etc/passwd" file to the WC command3.2. Output redirection
# Cat/etc/passwd> file overwrites the content in/ect/passwd to file
# Cat/etc/passwd> file: append the content in/etc/passwd to file.
# Aaa 2> errfile input the error result displayed by the aaa command to errfile
# Ls afile bfile &> allfile redirects the standard output and error output to the same file
# Ls/etc/passwd/| head-5 displays the first five lines of passwd content4. Shell script
# Ls-l/etc/init. d/The directory contains a large number of System Service start programs, all of which are Shell script files. You can use the file command to query the types of these files.
# Bash *. sh run the script using shell commands
#./Home/techer/filename. sh execute filename. sh

This article is from the blog of "the Linux open source technology blog", please be sure to keep this source http://dreamfire.blog.51cto.com/418026/159512


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.