Shell Primer-shelltexing

Source: Internet
Author: User
Tags aliases

1. About!

Command:!!

Description: Executes the previous command

[Email protected] ~]# pwd
/root
[[email protected] ~]#!!
Pwd
/root

Command:! N (n = number)

Description: Executes the nth command in the command history

Extended command: History

Description: View command history

[Email protected] ~]# history

.......

1058 vim. BASHRC
1059 pwd
1060 History

[Email protected] ~]#!1059
Pwd
/root

Command:! Character

Description:! P For example, executes the last command in the command history that begins with P

[Email protected] ~]#!p
Pwd
/root

/////////////////////////////////////////////////////////////////////////////////////////////////////////

2. About command aliases

Command: Alias "command alias" = "' Specific Command '"

Description: Customize a name to the command, the current shell is valid

Command: Unalias "command alias"

Description: Canceling command aliases

[[email protected] ~]# alias denny= ' pwd '
[Email protected] ~]# Denny
/root

[Email protected] ~]# Unalias Denny
[Email protected] ~]# Denny
-bash:denny:command not found

//////////////////////////////////////////////////////////////////////////////////////////////

3. About redirection

Command:>

Description: Output Redirect, delete the contents of the file, write the new

[email protected] 111]# cat 1.txt
1111
[Email protected] 111]# echo ' 222 ' >1.txt
[email protected] 111]# cat 1.txt
222

Command:>>

Description: Append redirect, write on the original base of the file below

[Email protected] 111]# echo ' 333 ' >>1.txt
[email protected] 111]# cat 1.txt
222
333

Command:<

Description: Enter the redirect to enter the contents of the file to the front

[Email protected] 111]# Wc-l<1.txt
2

Command:2>;2>>

Description: Error redirection, append error redirection. Redirect or append the wrong content to a file

[[email protected] 111]# ls 5 2> 1.txt
[email protected] 111]# cat 1.txt
LS: Unreachable 5: No file or directory

[[email protected] 111]# ls 5 2>> 1.txt
[email protected] 111]# cat 1.txt
LS: Unreachable 5: No file or directory
LS: Unreachable 5: No file or directory

//////////////////////////////////////////////////////////////////////////////////////////////////////

4. About Pipe breaks

Command: "full command" | "command"

Description: Throw the result from the previous command to the command following the pipe symbol to process

[email protected] 111]# Cat 1.txt | Wc-l
3

[[email protected] 111]# ls
1 11.txt 1.txt
[[email protected] 111]# ls./*.txt | Xargs RM-RF
[[email protected] 111]# ls
1

//////////////////////////////////////////////////////////////////////////////////////////////

5. About wildcard Match characters

Command: *

Description: can represent multiple characters

[[email protected] 111]# ls
1 11.txt 1.txt 22.txt 2.txt 33.txt 3.txt 44.zip 55.zip
[[email protected] 111]# ls *.txt
11.txt 1.txt 22.txt 2.txt 33.txt 3.txt

Command:?

Description: Represents a character

[[email protected] 111]# ls
1 11.txt 1.txt 22.txt 2.txt 33.txt 3.txt 44.zip 55.zip
[email protected] 111]# ls?. Txt
1.txt 2.txt 3.txt

//////////////////////////////////////////////////////////////////////////////////////////

6. About process pause, view pause, resume, background run, end process

Shortcut key: Ctrl + Z

Description: Process paused

[[email protected] 111]# Sleep 100
^z
[1]+ Stopped Sleep 100

[[email protected] 111]# Sleep 200
^z
[2]+ Stopped Sleep 200

Command: Jobs

Description: View the paused process,

[[email protected] 111]# jobs
[1]-Stopped Sleep 100
[2]+ Stopped Sleep 200

Command: FG;FG "number"

Description: Resume the pause process, followed by a plus sign with a priority recovery,-number second, you can also resume the process in the specified pause

[[email protected] 111]# FG
Sleep 200

^z

[2]+ Stopped Sleep 200

[[email protected] 111]# jobs
[1] Stopped sleep 100
[2]-Stopped Sleep 200
[3]+ Stopped Sleep 300
[[email protected] 111]# FG 2
Sleep 200
^z
[2]+ Stopped Sleep 200

Command: BG;BG "number"

Description: The background runs the pause process, the number followed by the plus sign of the priority background run,-number second, you can also specify a process in the background run pause & indicate background run

[[email protected] 111]# BG 2
[2]-Sleep &
[[email protected] 111]# jobs
[1]-Stopped Sleep 100
[2] Running Sleep &
[3]+ Stopped Sleep 300

Shortcut keys: Ctrl + C

Description: End Process

[[email protected] 111]# FG
Sleep 300
^c

///////////////////////////////////////////////////////////////////////////////////////////////////////////

7. Closed the current shell, how to end the process

Command: PS aux

Description: View Process

[[Email protected] 111]# PS aux |grep sleep
Root 1693 0.0 0.0 100904 596 pts/0 T 21:32 0:00 sleep 100
Root 1697 0.0 0.0 100904 596 pts/0 T 21:36 0:00 sleep 100000
Root 1703 0.0 0.0 103252 880 pts/0 s+ 21:38 0:00 grep sleep

Command: Kill

Option:-9: Mandatory

Description: End Process

[Email protected] 111]# kill-9 1697
[3]+ has killed sleep 100000

////////////////////////////////////////////////////////////////////////////////////////////////

Summarize:!! ! N//!  *//alias unalias//> >> < 2> 2>>//*? CTRL + Z FG BG Jobs CTRL + C/PS aux kill//

Shell Primer-shelltexing

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.