"Learn Linux with Amin" chapter 10th Shell Basics: After-school exercises and answers

Source: Internet
Author: User

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


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?
should be ps1= ' [\[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.
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:-f3/etc/passwd


6. Brief description of the role of these documents:/etc/profile,/ETC/BASHRC,. BASHRC,. Bash_profile.
    • /etc/profile : Sets the system global environment variable and startup program, and 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.

    • /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.

    • . Bash_profile : Defines 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.

    • . 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 that can make the declared variables effective in the child shell.


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?

To throw a running command into the background, you can press CTRL + Z to pause it, then use the BG command to run it in the background, or add & background ID when executing the command, in the form "Command + Space +&".

The process that runs in the background is transferred to the foreground, and you can enter the FG shortcut key.


10. List the files and directories in the current directory that begin with "test".
LS 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 & leaf Baidu Note: 2>&1 refers to specifying the standard information output path as the error message output path (that is, all output together).


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 bigfilesplit-l 10000 bigfile


15. Do the experiment, understand; && | | The meaning of these three symbols.
    • ; : Just for splitting multiple commands, each command runs independently of each other, without any correlation.

    • &&: Only the previous command will execute after it has been successfully executed. If the previous command execution fails, the following command is ignored.

    • || : If one command executes successfully in multiple commands, the following command is ignored, otherwise the following command is run.


16. What if you just want to let a user use a variable?
VIM/HOME/USERNAME/.BASHRC add a line 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


This article is from the "fragrant fluttering leaves" blog, please make sure to keep this source http://xpleaf.blog.51cto.com/9315560/1893506

"Learn Linux with Amin" chapter 10th Shell Basics: After-school exercises and answers

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.