Class exercises on environment variables

Source: Internet
Author: User

1. Set the environment variable histsize so that it can save 10,000 command history.


2. Why if this setting PS1 (ps1= "[\[email protected]\h \w]\$") displays the results and our


If not, how do you set it up to restore the original default?


3. Find ways to replace all lowercase letters in the file names of files in the current directory with capital letters


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


5. Use cut to ":" As the delimiter, truncate the third paragraph of the/etc/passwd character.


6. Brief description of the role of these documents:/etc/profile,/ETC/BASHRC,. BASHRC,


7. What is the role of export?


8. What are the rules for a custom variable under Linux?


9. How do I drop commands to run in the background? And how to transfer the background running process to the front desk?


10. List the files and directories in the current directory that begin with "test".


11. How can I print the output of a command not only on the screen but also in a file?


12. If an order is long, how do we use a simple string instead of this complex command? Please illustrate.


13. How do I implement this function, throw a command into the background and run it correctly


The output and error outputs are simultaneously redirected to a file?


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)?


15. Do the experiment, understand; && | | The meaning of these three symbols.


16. What if you just want to let a user use a variable?


17. Which command will be used to list all the variables in the system and the current user defined custom variables?


========================================================================================


1. Vim/etc/profile changed histsize=1000 to histsize=10000

2. Should be ps1= ' [\[email protected]\h \w]\$ ' = = ps1= ' [\[email protected]\h \w]\\$ '


3. 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. SORT-T:-k5/etc/passwd


5. Cut-d:-f3/etc/passwd


6. /etc/profile : Set 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. Export to declare variables, you can make the declared variables in the child shell in effect


8. (1) The format of the set variable is "A=b", where a is the variable name, B is the contents 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, you need to add a single quotation mark, the variable content itself with a single quotation mark, 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. To drop 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.


Ten. Ls-d test*


11. Use the tee command, such as CAT/ETC/PASSWD |tee 2.txt


12. Use alias like alias abc= "/usr/local/apache/bin/apachectl-t"


Vmstat 1 >/tmp/1.log 2>&1 &


Split-b 10M bigfile split-l 10000 bigfile


15.; 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. The previous command execution failed, ignoring the subsequent command.

|| As soon as one command executes successfully in multiple commands, the following command is ignored, or the following command is run.


VIM/HOME/USERNAME/.BASHRC add a row of export abc=123

And then SOURCE/HOME/USERNAME/.BASHRC.


17.set



Class exercises on environment variables

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.