1. Set the environment variable histsize so that it can save 10,000 command history.
A: Vim/etc/profile, search for histsize, change 1000 to 10000, then save the exit, and then execute source/etc/profile to make it effective.
[Email protected] ~]# echo $HISTSIZE
1000
[[email protected] ~]# histsize=10000# temporarily modified
[Email protected] ~]# echo $HISTSIZE
10000
[Email protected] ~]# cat/etc/profile |grep histsize
histsize=1000
Export PATH USER LOGNAME MAIL HOSTNAME histsize Histcontrol
[[email protected] ~]# vim/etc/profile# permanently modified
histsize=10000
Esc:wq
[Email protected] ~]# Source/etc/profile
[Email protected] ~]# echo $HISTSIZE
10000
[Email protected] ~]#
2. Why does setting PS1 (ps1= "[\[email protected]\h \w]\$") show a different result than we expected, and how do I set it to restore the original default?
A: The double quotation marks in the shell preserve the special meaning of the original character, and the single quotation mark can remove the special meaning of the original character. So we have two methods of modification: (1) ps1= "[\[email protected]\h \w]\\$"
(2) ps2= ' [\[email protected]\h \w]\$ '
3. Find ways to replace all lowercase letters in the file names of the files in the current directory with capital letters.
A: Use a script to accomplish this goal:
[Email protected] ~/test 01:04 #10]# vim lower2upper.sh
#!/bin/sh
For i in ' ls '
Do
MV $i ' echo $i |tr ' [A-z] ' [A-z] '
Done
Esc:wq
[Email protected] ~/test 01:04 #10]#/bin/sh lower2upper.sh
4. Use sort to sort the 5th paragraph of the/etc/passwd file with ":" As a delimiter.
Answer: sort-t:-k5-n/etc/passwd# sorted by 5th paragraph
5. Use cut to ":" As the delimiter, truncate the third paragraph of the/etc/passwd character.
Answer: cut-d:-f3/etc/passwd# cut out the third paragraph
6. Brief description of the role of these documents:/etc/profile,/ETC/BASHRC,. BASHRC,. Bash_profile.
A: These are all configuration files.
/etc/profile System-level configuration files, where the variables are valid for all users;
/ETC/BASHRC a system-level bash variable profile, and any user running bash reads the contents of it.
. BASHRC: A user-level bash-related variable profile that is valid only for the current user and does not require a login, which is read by the main user running the command line.
The. Bash_profile user-level variable profile is only valid for the current user and is read after the user logs on.
7. What is the role of export?
A: Declare a variable to take effect after it enters the child shell
8. What are the rules for a custom variable under Linux?
A: The format of the custom variable is varname=value, there is no space on either side of the equal sign, and the variable name can only consist of letters, numbers, and underscores, and cannot begin with a number; custom variables should be lowercase, not the same as System system variables, function names, keywords, etc. When the contents of a variable have special characters (such as spaces), a single quotation mark is required, the contents of the variable are enclosed in single quotation marks, and double quotation marks are required;
9. How do I drop commands to run in the background? And how to transfer the background running process to the front desk?
A: Before running, "Command &" is available to run directly in the background, running commands, you can use jobs to view its PID, then use the "BG pid" command to move it to the background, or you can use "FG pid" to move it to the foreground.
10. List the files and directories in the current directory that begin with "test".
Answer: Ls-ld test*
11. How can I print the output of a command not only on the screen but also in a file?
Answer: Ls-ld test* |tee Ls.log
12. If an order is long, how do we use a simple string instead of this complex command? Please illustrate.
Answer: You can use alias Alias:alias ls= ' ls--color=auto ';
You can also use the variable: myls= ' ls--color=auto ', which is called with only a $ symbol: $myls
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?
Answer: 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)?
Answer: split-b 10M filename
SPLIT-L 10000 filename
15. Do the experiment, understand; && | | The meaning of these three symbols.
Answer: (1); end a command that can be used to write multiple commands on one line
(2) && logic with, the preceding statement is true before executing the following statement, the preceding statement is False
(3) | | Logical OR, the preceding statement is false to execute the following statement, and the preceding statement is not executed
16. What if you just want to let a user use a variable?
A: You can edit the. bashrc file in their home directory as the user, add a row of var=10, save and execute after exiting
source. BASHRC make it effective immediately.
17. Which command will be used to list all the variables in the system and the current user defined custom variables?
A: Env can only list system variables, set not only to list system variables, but also to list user variables.
1. Set the environment variable histsize so that it can save 10,000 command history.