The basic knowledge of the 13th chapter before you learn shell scripts

Source: Internet
Author: User

1. Set the environment variable histsize so that it can save 10,000 command history.
  vim/etc/profile  
change histsize=1000 to histsize=10000

2. Why do I set PS1 (ps1= "[\[email protected]\h \w]\$")    display the results to be different from what we expected, and how do I set it to restore the original default?
   should be ps1= ' [\[email protected]\h \w]$   '     (to use single quotes)

3. Find ways to replace all lowercase letters in the file names of the files in the current directory with capital letters.
For f in ' LS '; Do if echo $f |grep-q ' [A-z] ', then MV $f ' echo $f |tr ' [A-z] ' [A-z] '; fi;done

4. Use sort to sort the 5th paragraph of the/etc/passwd file with ":" As a delimiter.
SORT-T:-k5/etc/passwd

5. Use cut to ":" As the delimiter, truncate the third paragraph of the/etc/passwd character.
Cut-d:-F 3/ETC/PASSWD

6. Brief description of the role of these documents:/etc/profile,/ETC/BASHRC,. BASHRC,. Bash_profile.
A,/etc/profile: Sets the system global environment variable and the startup program, when the user logs on to Linux, the file is executed, and the shell's settings are collected from the configuration file of the/ETC/PROFILE.D directory. The default system global variables include path, USER, LOGNAME, MAIL, INPUTRC, HOSTNAME, Histsize, Umask, and so on.
B,/ETC/BASHRC: Execute this file for each user running the bash shell. When the bash shell is opened, the file is read. By default, this file is primarily pre-umask and PS1.
C,. Bash_profile: Define user-specific environment variables and startup programs. When the user logs on, the file is executed only once. By default, it sets some environment variables to execute the user's. bashrc file.
d. BASHRC: This file contains bash information dedicated to the user's shell, which is read when the user logs on and every time a new shell is opened. User-defined alias and variables can be written to this file.

7. What is the role of export?
Export is used to declare variables globally, allowing declared variables to take effect in child shells

8. What are the rules for a custom variable under Linux?
(1) The format of the set variable is "A=b", where a is the variable name, B is the content of the variable, there can be no space on either side of the equal sign;
(2) variable names can only consist of English, numerals and underscores, and cannot begin with a number;
(3) when the contents of a variable with a special character (such as a space), you need to add a single quotation mark, the variable content itself with single quotation marks, the use of double quotation marks;
(4) If the variable content needs to use other commands to run the result, you can use the anti-quote;
(5) Variable content can accumulate the contents of other variables, need double quotation marks.

9. How do I drop commands to run in the background? And how to transfer the background running process to the front desk?
A, to throw the running command to the background, you can press CTRL + Z to pause it, and then use the BG command to run it in the background, or to execute the command when the & background identity, in the form of "Command + Space +&".

b, the background running process to the foreground, you can enter the FG shortcut key.

10. List the files and directories in the current directory that begin with "test".
Ls-d test*
11. How can I print the output of a command not only on the screen but also in a file?
using the tee command, such as CAT/ETC/PASSWD |tee 2.txt

12. If an order is long, how do we use a simple string instead of this complex command? Please illustrate.
Use alias like alias abc= "/usr/local/apache/bin/apachectl-t"

13. How do I implement this function by throwing a command into the background and redirecting its correct output and error output to a file at the same time?
Vmstat 1 >/tmp/1.log 2>&1 &

14. How do I divide a large file by size (if it is 10M), and how do I divide it by the number of rows (if 10000 rows)?
Split-b 10M file;

Split-l 10000 File

15. Do the experiment, understand; && | | The meaning of these three symbols.
 ; Just to split multiple commands, each command runs independently of each other, without any correlation.
&& only the previous command executes successfully, and subsequent commands do. If the previous command execution fails, the following command is ignored.
|| As soon as one command executes successfully in multiple commands, the following command is ignored, or the following command is run.

16. What if you just want to let a user use a variable?
VIM/HOME/USERNAME/.BASHRC Add a row of export abc=123
and then SOURCE/HOME/USERNAME/.BASHRC .
17. Which command will be used to list all the variables in the system and the current user defined custom variables?
Set


Extended reading:

"PS1" of Linux environment variablesHttp://www.lishiming.net/thread-5364-1-1.html

Linux supports ChineseHttp://www.lishiming.net/thread-5360-1-1.html

keep command history permanently saved and timestampHttp://www.lishiming.net/thread-283-1-1.html

Linux under/etc/profile,/ETC/BASHRC, ~/.bash_profile, ~/.BASHRC do whatHttp://www.lishiming.net/thread-909-1-1.html

The basic knowledge of the 13th chapter before you learn shell scripts

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.