Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Common commands under shell

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

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

# help / / View all built-in commands

# help built-in commands / / View how to use built-in commands

# help-s built-in commands / / shows the syntax format of built-in commands, which is very easy to use!

[root@localhost var] # help-s cd

Cd: cd [- L |-P] [dir]

2.echo is used to display a line of text, which wraps automatically by default.

[root@localhost ~] # echo www

Www

-e makes the special characters in the string work. For example:

[root@localhost ~] # echo-e "I am the king\ nof the world."

The implementation results are as follows:

I am the king

Of the world.

Where\ nwill be translated into newline characters.

3.printf displays the content of parameters in the format

Suppose the variable str= "Hello World"

[root@localhost ~] # printf "% s\ n"$str"

Hello World

# displays the contents of the variable str and\ nhas the effect of line wrapping.

[root@localhost ~] # printf "% c\ n"$str"

H

# display the first character of the variable value

[root@localhost ~] # printf "% s has% d characters\ n"$str" 11

There are 11 characters in Hello World.

# shows that the str= "Hello world" has 11 characters.

[root@localhost ~] # printf "% 9s\ n" Hello!

_ Hello!

# displays a string of 9 characters (aligned to the right), and the part of less than 9 characters is filled with a space character. The result shows "_ Hello!" (there are 3 spaces on the left) [root@localhost ~] # printf "%-9s\ n" Hello!

# displays a string with a length of 9 characters (aligned to the left), and the parts less than 9 characters are completed with a space character, resulting in the display of "Hellographies characters _"

[root@localhost ~] # printf "% 5.8f\ n" 300

300.00000000

# in the above string, 5 in 5.8 indicates a total of 5 digits including decimal places, and 8 in 5.8 indicates that decimal places occupy one place.

[root@localhost ~] # printf "% Q\ n"$str"

"Hello\ world"

# the% Q parameter here is to escape special characters

[root@localhost ~] # printf-v myvar "% Q"ABC 123 XYZ"

The-v here means: do not display to standard output, but give the value of what you want to display to the variable myvar.

# myvar variable is "ABC\ 123\ XYZ"

[root@localhost ~] # printf "% b"ABC\ n123\ nXYZ\ n"

#% b means that the escape of special characters takes effect, that is, the n in the string will have a line break effect

# results are as follows: ABC

one hundred and twenty three

XYZ

[root@localhost ~] # printf "% s\ n"ABCDEFGHIJK" | tr Amurz

# display the string, pipe it to tr, and convert the uppercase letters to lowercase.

# result: display abcdefghijk

4.cd changes directory location

[root@localhost ~] cd

# return to home directory after execution, which is equivalent to cd ~

[root@localhost] cd-

[root@dns2 ~] # cd / var/log

[root@dns2 log] # cd-

/ root

[root@dns2 ~] #

# return to the previous directory

[root@localhost] cd..

# go back to the previous directory

5.pwd displays the current working directory

[root@localhost ~] pwd

/ root

# display the current work path

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

[root@localhost ~]: > aa

You can create an empty file named aa

7.. (half-corner full stop) execute shell programs in the current shell environment

[root@localhost]. Aa.sh

Note:。 Add at least one space prompt to the shell program.

. Has the same effect as the source command

8.source executes shell programs in the current shell environment

[root@localhost ~] source aa.sh

9.alias display, set program alias

[root@localhost ~] alias

# after execution, display the names of all currently set programs.

[root@localhost] alias help1='help-s test'

# alias new alias = "combined program"

[root@localhost ~] alias cp=cp

# cancel the program alias, cp is still the original cp command (default is cp-I).

10.unalias

[root@localhost ~] unalias cp

# means to cancel the alias setting of cp

11.exit leaves bash shell or ends the Script program

Leave shell and return a value of 1

12.logout logs out of login shell

In the case of no string input on the command line, if you press the [ctrl D] key combination, its function is equivalent to the logout instruction, and you can also log out.

13.umask displays or sets the permission mask for new files and directories

[root@localhost ~] umask

# display the current umask mask after execution

[root@localhost] umask-S 0024

# after execution, set the umask mask to 0024

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

[root@localhost~] histroy

# execution result, showing commands that have been executed by the linux host

Histroy variable:

HISTFILE View History File name and Storage path

[root@localhost~] echo $HISTFILE

/ root/.bash_history

HISTFILESIZE to view the number of files stored

[root@localhost~] echo $HISTFILESIZE

one thousand

The number of historical commands saved by HISTSIZE under the current shell

[root@localhost~] echo $HISTSIZE

one thousand

15.fc lists the most recent commands executed after logging in to the host

[root@localhost~] fc-l

# display the most recent commands executed after login

[root@localhost~] fc-ln

# do not display the command number

[root@localhost~] fc-l ll cp

# display historical commands between ll and cp commands

You can also use numbers, such as:

[root@localhost~] fc-l 400500

[root@localhost~] fc-lr 400500

Display commands according to the number from large to small

16.type determines how bash interprets an instruction (I think the function of this command is to check the type of command)

[root@localhost ~] # type fg

Fg is a shell builtin / / fg is a shell built-in name in

[root@localhost ~] # type if

If is a shell keyword / / if is a reserved field of shell

[root@localhost ~] # type cp

Cp is aliased to `cp-i' / / cp is the program alias of'cp-i'

[root@localhost ~] # type tr

Tr is / usr/bin/tr / / tr is an independent execution program, and the program path is / usr/bin/tr

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

[root@localhost~] set

# View current shell environment variables and functions

[root@localhost~] set-o | grep on

[root@dns9 ~] # set-o | grep on

Braceexpand on

Emacs on

Hashall on

Histexpand on

History on

Interactive-comments on

Monitor on

Onecmd off

# check the switch status of all the current shell attributes

# start an attribute of bash shell:

[root@localhost~] set-o emacs (attribute name)

# disable the attribute of a bash shell:

[root@localhost~] set + o emacs (attribute name)

# protect existing files from overwriting the contents of the file when diverting to output.

[root@localhost~] set-o noclobber

[root@localhost ~] # echo 22 > aaa.txt

-bash: aaa.txt: cannot overwrite existing file

[root@localhost~] set-v

This option causes bash to display every process code it reads when it executes Script, which is usually used for program troubleshooting.

18.shopt sets the behavior mode of Bash Shell (similar to the set command)

[root@localhost~] shopt

# displays the current switch status of each option, which is the same as that of shopt-p

[root@localhost~] shopt-s

# enable option

[root@localhost~] shopt-u

# turn off option

[root@localhost~] shopt-o

# use the same options as set-o to set

[root@localhost~] shopt-Q

# do not display the switch status, judge whether the option is on or off by the return status, enable the 0 table and close the 1 table

19.!! Indicates the execution of the previous command

20. > indicates redirection and enters a value into the file

21. > append redirect, you can continue to append the file content in the file

twenty-two。

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report