Common commands under the shell

Source: Internet
Author: User
Tags uppercase letter

1.HELP displays a list of all built-in commands, or the use of a built-in command

    1. #help//View all built-in commands

    2. #help built-in commands//view built-in command usage

    3. #help-S built-in command//display the syntax format of the built-in commands, very useful Oh!

    4. [[email protected] var]# help-s CD

    5. CD:CD [-l|-p] [dir]

2.echo is used to display a line of text and is automatically wrapped by default

    1. [Email protected] ~]# echo www

    2. Www

    3. -E lets special characters in a string work. For example:

    4. [[Email protected] ~] #echo-E "I am the King\nof the world."

    5. The results of the implementation are as follows:

    6. I am the King
      of the world.

    7. where \ n is translated into a newline character.

3.printf Display parameter contents according to format

  1. Suppose the variable str= "Hello World"

  2. [[Email protected] ~] #printf "%s\n" "$str"

  3. Hello World

  4. #显示变量str的内容, and \ n has a line-wrapping effect.

  5. [[Email protected] ~] #printf "%c\n" "$str"

  6. H

  7. #显示变量值的第一个字符

  8. [[Email protected] ~] #printf "%s total%d characters \ n" "$str" 11

  9. Hello World A total of 11 characters

  10. #显示str = "Hello World" has a total of 11 characters.

  11. [[Email protected] ~] #printf "%9s\n" hello!

  12. ___hello!

  13. #显示9个字符长度的字符串 (right-aligned), the part with less than 9 characters is padded with whitespace, and the results show "___hello!" (3 characters left) [[Email protected] ~] #printf "%-9s\n" hello!

#显示9个字符长度的字符串 (left-aligned), a portion of less than 9 characters is padded with whitespace, resulting in "hello!___"

[[Email protected] ~] #printf "%5.8f\n" 300

300.00000000

The #在上述的字符串中, 5.8 of 5, indicates a total of 5 digits with a decimal point, and 5.8 in 8 means that the number of small digits occupies one bit.

[[Email protected] ~] #printf "%q\n" "$str"

"Hello\world"

#这里的%q parameter is to escape special characters

[[Email protected] ~] #printf-v myvar "%q" "ABC 123 XYZ"

#这里的-V is said: Do not display to the standard output, and the value of the content you want to display to the variable myvar.

#myvar变量为 "ABC\123\XYZ"

[[Email protected] ~] #printf "%b" "abc\n123\nxyz\n"

#%b is to say that the special character escape takes effect, which means that n in the string will have a newline effect.

#结果如下: ABC

123

Xyz

[[Email protected] ~] #printf "%s\n" "Abcdefghijk" |tr A-Z

#把字符串显示出来, pass the pipe to TR and turn the uppercase letter into lowercase.

#结果: Show Abcdefghijk

4.CD Changing directory Location

[Email protected] ~]cd

#执行后回到家目录, equivalent to CD ~

[Email protected] ~]CD-

[Email protected] ~]# Cd/var/log
[Email protected] log]# CD-
/root
[Email protected] ~]#

#回到先前的目录

[Email protected] ~]CD.

#回到上一层目录

5.PWD displays the current working directory

    1. [Email protected] ~]pwd

    2. /root

    3. #显示当前工作路径

6.:(colon) do nothing, return the true value (that is, return 0)

    1. [[Email protected] ~]: >AA

    2. You can create an empty file with a name of AA

7.. (Half-width period) Execute Shell program in the current shell environment

    1. [[Email protected] ~]. aa.sh

    2. Note: You must add at least one space prompt to the shell program.

    3. The same function as the source command

8.source executing shell programs in the current shell environment

    1. [Email protected] ~]source aa.sh

9.alias display, set program alias

    1. [Email protected] ~]alias

    2. #执行后, displays all currently set program names.

    3. [Email protected] ~]alias help1= ' help-s test '

    4. #alias New alias = "Combined Program"

    5. [Email protected] ~]alias CP=CP

    6. #取消程序别名, CP is also the original CP command (default is Cp-i).

10.unalias

    1. [email protected] ~]unalias CP

    2. #表示把cp的别名设定取消

11.exit leave bash shell or end script program

Leave the shell and return the value 1

12.logout Logout Login Shell

In the case where no strings are entered on the command line, pressing the [CTRL D] key combination is equivalent to the logout instruction and can be logged off.

13.umask Display or set permissions mask for new files and directories

    1. [Email protected] ~]umask

    2. #执行后, displays the current umask mask

    3. [[email protected] ~]umask-s 0024

    4. #执行后, set the umask mask to 0024

14.history shows shell commands that have been executed in the past

  1. [[Email Protected]~]histroy

  2. #执行结果, displays commands that have been executed by a Linux host

  3. Histroy variables:

  4. Histfile View history file name and storage path

  5. [Email Protected]~]echo $HISTFILE

  6. /root/.bash_history

  7. Histfilesize viewing the number of files stored

  8. [Email Protected]~]echo $HISTFILESIZE

  9. 1000

  10. Histsize the number of history commands saved under the current shell

  11. [Email Protected]~]echo $HISTSIZE

  12. 1000

15.FC lists the most recently executed commands after logging in to the host

    1. [[email protected]~]fc-l

    2. Span style= "FONT-SIZE:16PX;" > #显示登录后最近执行过的命令

    3. [[email protected]~]fc-ln

    4. #不显示命令的编号

    5. [[ EMAIL PROTECTED]~]FC-L ll CP

    6. #显示ll和cp两条命令之间的历史命令

    7. [[email protected ]~]FC-LR

    8. show commands in large to small numbers

16.type determine how bash interprets an instruction (this command is the type of command you see)

    1. FG is a shell builtin   //FG is a shell's built-in name in a

    2. [[email protected] ~]# type if

    3. if is a shell keyword  //if a reserved field for the shell

    4. [[email protected] ~]# type CP

    5. CP is aliased to ' cp-i '  //CP ' cp-i ' program alias

    6. [[email protected] ~]# type tr 

    7. tr is/usr/bin/tr     //tr is a standalone execution program with the program path/usr/bin /tr

17.set sets the properties of the bash shell and, without any options and arguments, displays the contents of all shell variables and functions.

  1. [[Email Protected]~]set

  2. #查看当前shell环境变量和函数

  3. [[Email Protected]~]set-o|grep on

  4. [Email protected] ~]# Set-o|grep on

  5. Braceexpand on

  6. Emacs on

  7. Hashall on

  8. Histexpand on

  9. History on

  10. Interactive-comments on

  11. Monitor on

  12. Onecmd off

  13. #查看目前shell所有的属性的开关状态

  14. #开始一个bash the properties of the shell:

  15. [[Email protected]~]set-o emacs (attribute name)]

  16. #关闭一个bash the properties of the shell:

  17. [[Email Protected]~]set +o emacs (attribute name)

  18. #保护已存在的文件, avoid overwriting the contents of the file when turning the output.

  19. [[Email Protected]~]set-o noclobber

  20. [Email protected] ~]# echo > Aaa.txt

  21. -bash:aaa.txt:cannot Overwrite existing file

  22. [[Email Protected]~]set-v

  23. #这个选项会使bash执行Script时, each process code that it reads into is displayed and is usually used for program troubleshooting.

18.shopt set the behavior mode of the bash shell (similar to the SET command)

    1. [[Email protected]~]shopt

    2. #显示目前各选项的开关状态, the same effect as shopt-p execution

    3. [[Email Protected]~]shopt-s

    4. #启用选项

    5. [[Email Protected]~]shopt-u

    6. #关闭选项

    7. [[Email Protected]~]shopt-o

    8. #使用和set-o same option to set

    9. [[Email Protected]~]shopt-q

    10. #不显示开关状态, the callback status option is on or off, 0 table enabled, 1 table off


.!! Represents the execution of the previous command


> redirect, enter a value into the file


>> Follow-up redirect, you can continue to append file content in the file


< reverse redirect, throw a command to the file


23.last commands can see which 650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/ U261/lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "spacer.gif"/>ip logged into the Linux system


Common commands under the shell

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.